UNPKG

thorish

Version:

This is a library of useful JS concepts and data structures for Node and the browser. It it, unashamedly, a dumping ground for code needed by [@samthor](https://twitter.com/samthor)'s projects.

25 lines (24 loc) 1.04 kB
export type AsyncIntermediateReturn<T, Y = void> = { /** * Generator which yields values sent into it as a queue. */ gen: AsyncGenerator<T, Y, void>; /** * Sends a value into the generator, returning a {@link Promise} that resolves when the generator * resumes after the corresponding yield. * * Users of the generator must be careful to always ask for a further value, e.g., via a * `for await` loop. */ send: (update: T | PromiseLike<T>) => Promise<void>; /** * Stops the generator, causing the user of it to recieve the passed return value. All previous * sends are allowed to complete first. Unlike {@link AsyncIntermediateReturn#send}, this * resolves before the generator "yields" the return value. */ stop: (final: Y | PromiseLike<Y>) => Promise<void>; }; /** * Builds a {@link AsyncGenerator} which only allows one value to be queued at a time. */ export declare function buildAsyncIntermediate<T, Y = void>(): AsyncIntermediateReturn<T, Y>;