Son CV dans un terminal web en Javascript!
https://terminal-cv.gregandev.fr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
1 year ago
|
'use strict';
|
||
|
// https://github.com/tc39/proposal-iterator-helpers
|
||
|
var $ = require('../internals/export');
|
||
|
var apply = require('../internals/function-apply');
|
||
|
var anObject = require('../internals/an-object');
|
||
|
var toPositiveInteger = require('../internals/to-positive-integer');
|
||
|
var createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');
|
||
|
|
||
|
var AsyncIteratorProxy = createAsyncIteratorProxy(function (Promise, args) {
|
||
|
var state = this;
|
||
|
|
||
|
return new Promise(function (resolve, reject) {
|
||
|
var loop = function () {
|
||
|
try {
|
||
|
Promise.resolve(
|
||
|
anObject(apply(state.next, state.iterator, state.remaining ? [] : args))
|
||
|
).then(function (step) {
|
||
|
try {
|
||
|
if (anObject(step).done) {
|
||
|
state.done = true;
|
||
|
resolve({ done: true, value: undefined });
|
||
|
} else if (state.remaining) {
|
||
|
state.remaining--;
|
||
|
loop();
|
||
|
} else resolve({ done: false, value: step.value });
|
||
|
} catch (err) { reject(err); }
|
||
|
}, reject);
|
||
|
} catch (error) { reject(error); }
|
||
|
};
|
||
|
|
||
|
loop();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
$({ target: 'AsyncIterator', proto: true, real: true }, {
|
||
|
drop: function drop(limit) {
|
||
|
return new AsyncIteratorProxy({
|
||
|
iterator: anObject(this),
|
||
|
remaining: toPositiveInteger(limit)
|
||
|
});
|
||
|
}
|
||
|
});
|