| 53 | |
| 54 | // Create a yield() function tailored for this iterator. |
| 55 | var yield_ = expr => { |
| 56 | |
| 57 | // Ensure this function is executing inside a fiber. |
| 58 | if (!Fiber.current) { |
| 59 | throw new Error( |
| 60 | 'await functions, yield functions, and value-returning suspendable ' + |
| 61 | 'functions may only be called from inside a suspendable function. ' |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | // Notify waiters of the next result, then suspend the iterator. |
| 66 | if (runContext.callback) runContext.callback(null, { value: expr, done: false }); |
| 67 | if (runContext.resolver) runContext.resolver.resolve({ value: expr, done: false }); |
| 68 | Fiber.yield(); |
| 69 | } |
| 70 | |
| 71 | // Insert the yield function as the first argument when starting the iterator. |
| 72 | startupArgs[0] = yield_; |
no test coverage detected