-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
esnext.async-iterator.from.js
30 lines (27 loc) · 1.04 KB
/
esnext.async-iterator.from.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// https://github.com/tc39/proposal-iterator-helpers
var $ = require('../internals/export');
var path = require('../internals/path');
var aFunction = require('../internals/a-function');
var anObject = require('../internals/an-object');
var toObject = require('../internals/to-object');
var createAsyncIteratorProxy = require('../internals/create-async-iterator-proxy');
var getAsyncIteratorMethod = require('../internals/get-async-iterator-method');
var AsyncIterator = path.AsyncIterator;
var AsyncIteratorProxy = createAsyncIteratorProxy(function (arg) {
return anObject(this.next.call(this.iterator, arg));
}, true);
$({ target: 'AsyncIterator', stat: true }, {
from: function from(O) {
var object = toObject(O);
var usingIterator = getAsyncIteratorMethod(object);
var iterator;
if (usingIterator != null) {
iterator = aFunction(usingIterator).call(object);
if (iterator instanceof AsyncIterator) return iterator;
} else {
iterator = object;
} return new AsyncIteratorProxy({
iterator: iterator
});
}
});