Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AwaitAll ¶
func AwaitAll[T future](futures ...T) error
Await for multiple futures, Return nil if no future returns error, or return the first error in these futures.
func WarmupPool ¶
WarmupPool do warm up logic for each goroutine in pool
Types ¶
type Future ¶
type Future[T any] struct { // contains filtered or unexported fields }
Future is a result type of async-await style. It contains the result (or error) of an async task. Trying to obtain the result (or error) blocks until the async task completes.
func Go ¶
Go spawns a goroutine to execute fn, returns a future that contains the result of fn. NOTE: use Pool if you need limited goroutines.
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
A goroutine pool
func NewDefaultPool ¶
NewDefaultPool returns a pool with cap of the number of logical CPU, and pre-alloced goroutines.
func NewPool ¶
func NewPool[T any](cap int, opts ...PoolOption) *Pool[T]
NewPool returns a goroutine pool. cap: the number of workers. This panic if provide any invalid option.
type PoolOption ¶
type PoolOption func(opt *poolOption)
PoolOption options function to setup pool.
func WithConcealPanic ¶
func WithConcealPanic(v bool) PoolOption
func WithDisablePurge ¶
func WithDisablePurge(v bool) PoolOption
func WithExpiryDuration ¶
func WithExpiryDuration(d time.Duration) PoolOption
func WithNonBlocking ¶
func WithNonBlocking(v bool) PoolOption
func WithPreAlloc ¶
func WithPreAlloc(v bool) PoolOption