Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
849 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | // https://github.com/tc39/proposal-iterator-helpers
|
---|
3 | var $ = require('../internals/export');
|
---|
4 | var anObject = require('../internals/an-object');
|
---|
5 | var createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');
|
---|
6 |
|
---|
7 | var AsyncIteratorProxy = createAsyncIteratorProxy(function (arg, Promise) {
|
---|
8 | var state = this;
|
---|
9 | var iterator = state.iterator;
|
---|
10 |
|
---|
11 | return Promise.resolve(anObject(state.next.call(iterator, arg))).then(function (step) {
|
---|
12 | if (anObject(step).done) {
|
---|
13 | state.done = true;
|
---|
14 | return { done: true, value: undefined };
|
---|
15 | }
|
---|
16 | return { done: false, value: [state.index++, step.value] };
|
---|
17 | });
|
---|
18 | });
|
---|
19 |
|
---|
20 | $({ target: 'AsyncIterator', proto: true, real: true }, {
|
---|
21 | asIndexedPairs: function asIndexedPairs() {
|
---|
22 | return new AsyncIteratorProxy({
|
---|
23 | iterator: anObject(this),
|
---|
24 | index: 0
|
---|
25 | });
|
---|
26 | }
|
---|
27 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.