Documentation
¶
Index ¶
- func ChanCtx[T any](ctx context.Context, ch <-chan T) iter.Seq[T]
- func PoolRun2[R any](p *Pool, f func() (R, error)) <-chan Result[R]
- func Promise[R any](f func() (R, error)) func(context.Context) (R, error)
- func RecvCtx[T any](ctx context.Context, c <-chan T) (value T, ok bool)
- func Run(f func() error) <-chan error
- func Run2[R any](f func() (R, error)) <-chan Result[R]
- func SendCtx[T any](ctx context.Context, c chan<- T, value T) bool
- func WaitGroupRun2[R any](wg *WaitGroup, f func() (R, error)) <-chan Result[R]
- type Mutex
- type Pool
- type RWMutex
- func (m *RWMutex) Run(f func())
- func (m *RWMutex) RunE(f func() error) error
- func (m *RWMutex) RunENoPanic(f func() error) error
- func (m *RWMutex) RunERead(f func() error) error
- func (m *RWMutex) RunEReadNoPanic(f func() error) error
- func (m *RWMutex) RunNoPanic(f func())
- func (m *RWMutex) RunRead(f func())
- func (m *RWMutex) RunReadNoPanic(f func())
- type Result
- type Sem
- type WaitGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChanCtx ¶ added in v1.3.0
ChanCtx return iterator function that will yield values in the ch or until ctx is done.
similarity can be seen in the following code, but the later can be canceled by the context
for value := range ch {
// ...
}
for value := range async.ChanCtx(ctx, ch) {
// ...
}
func PoolRun2 ¶ added in v1.5.0
PoolRun2 similar to Pool.Run but also returning other value not just error.
func Promise ¶ added in v1.8.0
Run f in new goroutine, return a function that can be used concurrently to get the result, if f panic, the error value pass to panic will be returned.
func RecvCtx ¶ added in v1.7.0
RecvCtx waits for a value from the channel or until the context is done.
func Run ¶
Run the f function in new go routine, and return chan to get the value returned by f or the panic value if f panic.
func SendCtx ¶ added in v1.7.0
SendCtx sends a value to the channel or returns false if the context is done.
func WaitGroupRun2 ¶ added in v1.7.0
WaitGroupRun2 similar to WaitGroup.Run but also returning other value not just error.
Types ¶
type Mutex ¶ added in v1.6.0
func (*Mutex) Run ¶ added in v1.6.0
func (m *Mutex) Run(f func())
Run runs a function with mutex control.
func (*Mutex) RunENoPanic ¶ added in v1.12.0
func (*Mutex) RunNoPanic ¶ added in v1.8.0
func (m *Mutex) RunNoPanic(f func())
RunNoPanic is similar to Mutex.Run but assuming f will not panic.
if f panic, the mutex will not be unlocked.
type Pool ¶ added in v1.4.0
type Pool struct {
// contains filtered or unexported fields
}
type RWMutex ¶ added in v1.7.0
func (*RWMutex) Run ¶ added in v1.7.0
func (m *RWMutex) Run(f func())
Run runs a function with mutex control.
func (*RWMutex) RunENoPanic ¶ added in v1.12.0
func (*RWMutex) RunEReadNoPanic ¶ added in v1.12.0
func (*RWMutex) RunNoPanic ¶ added in v1.8.0
func (m *RWMutex) RunNoPanic(f func())
RunNoPanic is similar to RWMutex.Run but assuming f will not panic.
if f panic, the mutex will not be unlocked.
func (*RWMutex) RunRead ¶ added in v1.7.0
func (m *RWMutex) RunRead(f func())
RunRead runs a function with mutex control for read-only data.
func (*RWMutex) RunReadNoPanic ¶ added in v1.8.0
func (m *RWMutex) RunReadNoPanic(f func())
RunReadNoPanic is similar to RWMutex.RunRead but assuming f will not panic.
if f panic, the mutex will not be unlocked.
type Sem ¶ added in v1.5.0
type Sem struct {
// contains filtered or unexported fields
}
func (Sem) Run ¶ added in v1.6.0
func (s Sem) Run(f func())
Run runs a function with semaphore control.
func (Sem) RunNoPanic ¶ added in v1.8.0
func (s Sem) RunNoPanic(f func())
RunNoPanic is similar to Sem.Run but assuming f will not panic.
if f panic, the semaphore count will not be restored.