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:
963 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | // https://github.com/tc39/proposal-iterator-helpers
|
---|
3 | var $ = require('../internals/export');
|
---|
4 | var aFunction = require('../internals/a-function');
|
---|
5 | var anObject = require('../internals/an-object');
|
---|
6 | var createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');
|
---|
7 |
|
---|
8 | var AsyncIteratorProxy = createAsyncIteratorProxy(function (arg, Promise) {
|
---|
9 | var state = this;
|
---|
10 | var mapper = state.mapper;
|
---|
11 |
|
---|
12 | return Promise.resolve(anObject(state.next.call(state.iterator, arg))).then(function (step) {
|
---|
13 | if (anObject(step).done) {
|
---|
14 | state.done = true;
|
---|
15 | return { done: true, value: undefined };
|
---|
16 | }
|
---|
17 | return Promise.resolve(mapper(step.value)).then(function (value) {
|
---|
18 | return { done: false, value: value };
|
---|
19 | });
|
---|
20 | });
|
---|
21 | });
|
---|
22 |
|
---|
23 | $({ target: 'AsyncIterator', proto: true, real: true }, {
|
---|
24 | map: function map(mapper) {
|
---|
25 | return new AsyncIteratorProxy({
|
---|
26 | iterator: anObject(this),
|
---|
27 | mapper: aFunction(mapper)
|
---|
28 | });
|
---|
29 | }
|
---|
30 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.