-
-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathi-async.js
More file actions
38 lines (33 loc) · 657 Bytes
/
i-async.js
File metadata and controls
38 lines (33 loc) · 657 Bytes
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
31
32
33
34
35
36
37
38
'use strict';
const range = {
start: 1,
end: 1000,
[Symbol.asyncIterator]() {
let value = this.start;
return {
next: () => new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
value,
done: value++ === this.end + 1
});
}, 0);
})
};
}
};
console.dir({
range,
names: Object.getOwnPropertyNames(range),
symbols: Object.getOwnPropertySymbols(range),
});
let k = 0;
const timer = setInterval(() => {
console.log('next ', k++);
}, 10);
(async () => {
for await (const number of range) {
console.log(number);
}
clearInterval(timer);
})();