Executor replace go keyword to start a new goroutine
the goroutine should cancel itself if the context passed in has been cancelled
the goroutine started by the executor, is owned by the executor
we can cancel all executors owned by the executor just by stop the executor itself
however Executor interface does not Stop method, the one starting and owning executor
should use the concrete type of executor, instead of this interface. Go starts a new goroutine controlled by the context
*UnboundedExecutor
Map is a wrapper for sync.Map introduced in go1.9Mapsync.Map Clear deletes all the entries, resulting in an empty Map. CompareAndDelete deletes the entry for key if its value is equal to old.
The old value must be of a comparable type.
If there is no current value for key in the map, CompareAndDelete
returns false (even if the old value is the nil interface value). CompareAndSwap swaps the old and new values for key
if the value stored in the map is equal to old.
The old value must be of a comparable type. Delete deletes the value for a key.
If the key is not in the map, Delete does nothing. Load returns the value stored in the map for a key, or nil if no
value is present.
The ok result indicates whether value was found in the map. LoadAndDelete deletes the value for a key, returning the previous value if any.
The loaded result reports whether the key was present. LoadOrStore returns the existing value for the key if present.
Otherwise, it stores and returns the given value.
The loaded result is true if the value was loaded, false if stored. Range calls f sequentially for each key and value present in the map.
If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the Map's
contents: no key will be visited more than once, but if the value for any key
is stored or deleted concurrently (including by f), Range may reflect any
mapping for that key from any point during the Range call. Range does not
block other methods on the receiver; even f itself may call any method on m.
Range may be O(N) with the number of elements in the map even if f returns
false after a constant number of calls. Store sets the value for a key. Swap swaps the value for a key and returns the previous value if any.
The loaded result reports whether the key was present.
func NewMap() *Map
UnboundedExecutor is a executor without limits on counts of alive goroutines
it tracks the goroutine started by it, and can cancel them when shutdownHandlePanicfunc(recovered interface{}, funcName string) Go starts a new goroutine and tracks its lifecycle.
Panic will be recovered and logged automatically, except for StopSignal Stop cancel all goroutines started by this executor without wait StopAndWait cancel all goroutines started by this executor and wait.
Wait can be cancelled by the context passed in. StopAndWaitForever cancel all goroutines started by this executor and
wait until all goroutines exited
*UnboundedExecutor : Executor
func NewUnboundedExecutor() *UnboundedExecutor
var GlobalUnboundedExecutor *UnboundedExecutor
Package-Level Functions (total 2)
NewMap creates a thread safe Map
NewUnboundedExecutor creates a new UnboundedExecutor,
UnboundedExecutor can not be created by &UnboundedExecutor{}
HandlePanic can be set with a callback to override global HandlePanic
Package-Level Variables (total 4)
ErrorLogger is used to print out error, can be set to writer other than stderr
GlobalUnboundedExecutor has the life cycle of the program itself
any goroutine want to be shutdown before main exit can be started from this executor
GlobalUnboundedExecutor expects the main function to call stop
it does not magically knows the main function exits
HandlePanic logs goroutine panic by default
InfoLogger is used to print informational message, default to off
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.