Documentation ¶
Overview ¶
The package async defines asynchronous adapters.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chunk ¶
Chunk returns an iterator over consecutive values of up to n elements from seq.
The returned iterator reuses the buffer it yields. Apply mapper.Clone if the caller needs to retain slices.
Chunk may yield slices where 0 < len(s) <= n. Values may be shorter than n if timeout > 0 and the timeout duration passed since last time seq generated a value.
Chunk panics if n is less than 1.
func Map ¶
func Map[V1, V2 any]( ctx context.Context, queueLimit int, workerLimit int, mapper func(context.Context, V1) (V2, error), seq iter.Seq[V1], ) iter.Seq2[V2, error]
Map maps values from seq asynchronously.
Map applies mapper to values from seq in separate goroutines while keeping output order. When the order does not need to be kept, just send all values to workers through a channel using hiter.ChanSend and receive results via other channel using hiter.Chan.
queueLimit limits max amounts of possible simultaneous resource allocated. queueLimit must not be less than 1, otherwise Map panics. workerLimit limits max possible concurrent invocation of mapper. workerLimit is ok to be less than 1. When queueLimit > workerLimit, the total number of workers is only limited by queueLimit.
Cancelling ctx may stop the returned iterator early. mapper should respect the ctx, otherwise it delays the iterator to return.
If mapper panics Map panics with the first panic value.
The counter part of Map for iter.Seq2[K, V] does not exist since mapper is allowed to return error as second ret value. If you need to map iter.Seq2[K, V], convert it into iter.Seq[V] by hiter.ToKeyValue.
Types ¶
This section is empty.