Fetch the next result from the iterator.
(callback?: (err, result) => void)
| 28 | |
| 29 | /** Fetch the next result from the iterator. */ |
| 30 | next(callback?: (err, result) => void) { |
| 31 | |
| 32 | // Configure the run context. |
| 33 | if (this._acceptsCallback) { |
| 34 | this._runContext.callback = callback; // May be null, in which case it won't be used. |
| 35 | } |
| 36 | if (this._returnValue !== Config.NONE) { |
| 37 | var resolver = defer(); |
| 38 | this._runContext.resolver = resolver; |
| 39 | } |
| 40 | |
| 41 | // Remove concurrency restrictions for nested calls, to avoid race conditions. |
| 42 | if (FiberMgr.isExecutingInFiber()) this._semaphore = Semaphore.unlimited; |
| 43 | |
| 44 | // Run the fiber until it either yields a value or completes. For thunks, this is a lazy operation. |
| 45 | if (this._returnValue === Config.THUNK) { |
| 46 | var thunk: types.Thunk<any> = (done?) => { |
| 47 | if (done) resolver.promise.then(val => done(null, val), err => done(err)); |
| 48 | this._semaphore.enter(() => this._fiber.run(this._runContext)); |
| 49 | this._runContext.done = () => this._semaphore.leave(); |
| 50 | }; |
| 51 | } else { |
| 52 | this._semaphore.enter(() => this._fiber.run(this._runContext)); |
| 53 | this._runContext.done = () => this._semaphore.leave(); |
| 54 | } |
| 55 | |
| 56 | // Return the appropriate value. |
| 57 | switch (this._returnValue) { |
| 58 | case Config.PROMISE: return resolver.promise; |
| 59 | case Config.THUNK: return thunk; |
| 60 | case Config.RESULT: return await (resolver.promise); |
| 61 | case Config.NONE: return; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** Enumerate the entire iterator, calling callback with each result. */ |
| 66 | forEach(callback: (value) => void, doneCallback?: (err?) => void): any { |
no test coverage detected