Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Any ¶ added in v1.0.2
type Any = interface{}
Any is an alias for interface{} and is equivalent to interface{} in all ways.
type Cloneable ¶ added in v1.0.3
type Cloneable interface {
// Clone create and returns a copy of this object.
Clone() Any
}
Cloneable interface to support copy itself.
type Feature ¶ added in v1.0.2
type Feature interface {
// Complete notifies the parent coroutine that the task has completed and returns the execution result.
// This method is called by the child coroutine.
Complete(result Any)
// CompleteError notifies the parent coroutine that the task is terminated due to panic and returns stack information.
// This method is called by the child coroutine.
CompleteError(error Any)
// Get the execution result of the sub-coroutine, if there is no result, return nil.
// If panic is raised during the execution of the sub-coroutine, it will be raised again at this time.
// this method is called by the parent coroutine.
Get() Any
}
Feature provide a way to wait for the sub-coroutine to finish executing, get the return value of the sub-coroutine, and catch the sub-coroutine panic.
func GoWait ¶ added in v1.0.2
func GoWait(fun func()) Feature
GoWait starts a new goroutine, and copy inheritableThreadLocals from current goroutine. This function return a Feature pointer, so we can wait by Feature.Get method. If panic occur in goroutine, The panic will be trigger again when calling Feature.Get method.
func GoWaitResult ¶ added in v1.0.2
GoWaitResult starts a new goroutine, and copy inheritableThreadLocals from current goroutine. This function return a Feature pointer, so we can wait and get result by Feature.Get method. If panic occur in goroutine, The panic will be trigger again when calling Feature.Get method.
type StackError ¶ added in v1.0.2
type StackError interface {
// Message data when panic is raised.
Message() Any
// StackTrace stack when this instance is created.
StackTrace() string
// Error contains Message and StackTrace.
Error() string
}
StackError an error type contains stack info.
func NewStackError ¶ added in v1.0.2
func NewStackError(message Any) StackError
NewStackError create a new instance.
type Supplier ¶ added in v1.0.2
type Supplier = func() Any
Supplier provides a function which return Any type result.
type ThreadLocal ¶ added in v1.0.2
type ThreadLocal interface {
// Id returns the global id of instance.
Id() int
// Get returns the value in the current goroutine's local threadLocals or inheritableThreadLocals, if it was set before.
Get() Any
// Set copy the value into the current goroutine's local threadLocals or inheritableThreadLocals.
Set(value Any)
// Remove delete the value from the current goroutine's local threadLocals or inheritableThreadLocals.
Remove()
}
ThreadLocal provides goroutine-local variables.
func NewInheritableThreadLocal ¶ added in v1.0.2
func NewInheritableThreadLocal() ThreadLocal
NewInheritableThreadLocal create and return a new ThreadLocal instance. The initial value is nil. The value can be inherited to sub goroutines witch started by Go, GoWait, GoWaitResult methods.
func NewInheritableThreadLocalWithInitial ¶ added in v1.0.2
func NewInheritableThreadLocalWithInitial(supplier Supplier) ThreadLocal
NewInheritableThreadLocalWithInitial create and return a new ThreadLocal instance. The initial value is determined by invoking the supplier method. The value can be inherited to sub goroutines witch started by Go, GoWait, GoWaitResult methods.
func NewThreadLocal ¶ added in v1.0.2
func NewThreadLocal() ThreadLocal
NewThreadLocal create and return a new ThreadLocal instance. The initial value is nil.
func NewThreadLocalWithInitial ¶ added in v1.0.2
func NewThreadLocalWithInitial(supplier Supplier) ThreadLocal
NewThreadLocalWithInitial create and return a new ThreadLocal instance. The initial value is determined by invoking the supplier method.