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