(as: AsyncGenerator<A>)
| 1 | const NO_VALUE = Symbol('NO_VALUE') |
| 2 | |
| 3 | export async function lastX<A>(as: AsyncGenerator<A>): Promise<A> { |
| 4 | let lastValue: A | typeof NO_VALUE = NO_VALUE |
| 5 | for await (const a of as) { |
| 6 | lastValue = a |
| 7 | } |
| 8 | if (lastValue === NO_VALUE) { |
| 9 | throw new Error('No items in generator') |
| 10 | } |
| 11 | return lastValue |
| 12 | } |
| 13 | |
| 14 | export async function returnValue<A>( |
| 15 | as: AsyncGenerator<unknown, A>, |
nothing calls this directly
no outgoing calls
no test coverage detected