-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path6-next.js
More file actions
28 lines (25 loc) · 529 Bytes
/
Copy path6-next.js
File metadata and controls
28 lines (25 loc) · 529 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
'use strict';
const getNumbers = () => {
const numbers = [1, 2, 3];
return () =>
new Promise((resolve, reject) => {
const num = numbers.shift();
if (num) {
resolve(num);
} else {
reject(new Error('I have no numbers for you'));
}
});
};
// Usage
(async () => {
const getNext = getNumbers();
for (let i = 0; i < 5; i++) {
try {
const res = await getNext();
console.dir({ res });
} catch (err) {
console.dir({ err: err.message });
}
}
})();