(method, arg, resolve, reject)
| 20047 | |
| 20048 | function AsyncIterator(generator) { |
| 20049 | function invoke(method, arg, resolve, reject) { |
| 20050 | var record = tryCatch(generator[method], generator, arg); |
| 20051 | if (record.type === "throw") { |
| 20052 | reject(record.arg); |
| 20053 | } else { |
| 20054 | var result = record.arg; |
| 20055 | var value = result.value; |
| 20056 | if (value && |
| 20057 | typeof value === "object" && |
| 20058 | hasOwn.call(value, "__await")) { |
| 20059 | return Promise.resolve(value.__await).then(function(value) { |
| 20060 | invoke("next", value, resolve, reject); |
| 20061 | }, function(err) { |
| 20062 | invoke("throw", err, resolve, reject); |
| 20063 | }); |
| 20064 | } |
| 20065 | |
| 20066 | return Promise.resolve(value).then(function(unwrapped) { |
| 20067 | // When a yielded Promise is resolved, its final value becomes |
| 20068 | // the .value of the Promise<{value,done}> result for the |
| 20069 | // current iteration. If the Promise is rejected, however, the |
| 20070 | // result for this iteration will be rejected with the same |
| 20071 | // reason. Note that rejections of yielded Promises are not |
| 20072 | // thrown back into the generator function, as is the case |
| 20073 | // when an awaited Promise is rejected. This difference in |
| 20074 | // behavior between yield and await is important, because it |
| 20075 | // allows the consumer to decide what to do with the yielded |
| 20076 | // rejection (swallow it and continue, manually .throw it back |
| 20077 | // into the generator, abandon iteration, whatever). With |
| 20078 | // await, by contrast, there is no opportunity to examine the |
| 20079 | // rejection reason outside the generator function, so the |
| 20080 | // only option is to throw it from the await expression, and |
| 20081 | // let the generator function handle the exception. |
| 20082 | result.value = unwrapped; |
| 20083 | resolve(result); |
| 20084 | }, reject); |
| 20085 | } |
| 20086 | } |
| 20087 | |
| 20088 | if (typeof process === "object" && process.domain) { |
| 20089 | invoke = process.domain.bind(invoke); |
no test coverage detected