Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1017 bytes
|
Rev | Line | |
---|
[6a3a178] | 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 toPositiveInteger = require('../internals/to-positive-integer');
|
---|
| 6 | var createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');
|
---|
| 7 |
|
---|
| 8 | var AsyncIteratorProxy = createAsyncIteratorProxy(function (arg, Promise) {
|
---|
| 9 | var iterator = this.iterator;
|
---|
| 10 | var returnMethod, result;
|
---|
| 11 | if (!this.remaining--) {
|
---|
| 12 | result = { done: true, value: undefined };
|
---|
| 13 | this.done = true;
|
---|
| 14 | returnMethod = iterator['return'];
|
---|
| 15 | if (returnMethod !== undefined) {
|
---|
| 16 | return Promise.resolve(returnMethod.call(iterator)).then(function () {
|
---|
| 17 | return result;
|
---|
| 18 | });
|
---|
| 19 | }
|
---|
| 20 | return result;
|
---|
| 21 | } return this.next.call(iterator, arg);
|
---|
| 22 | });
|
---|
| 23 |
|
---|
| 24 | $({ target: 'AsyncIterator', proto: true, real: true }, {
|
---|
| 25 | take: function take(limit) {
|
---|
| 26 | return new AsyncIteratorProxy({
|
---|
| 27 | iterator: anObject(this),
|
---|
| 28 | remaining: toPositiveInteger(limit)
|
---|
| 29 | });
|
---|
| 30 | }
|
---|
| 31 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.