Skip to content

Commit aec3b17

Browse files
committed
Add multiple resolve example
1 parent 8da29ee commit aec3b17

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

JavaScript/8-multiple.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const sum = (a, b) => new Promise((resolve, reject) => {
4+
if (typeof a === 'number' && typeof b === 'number') {
5+
resolve(a + b);
6+
resolve(a + b);
7+
} else {
8+
reject(new Error('a and b should be numbers'));
9+
}
10+
});
11+
12+
process.on('multipleResolves', (type, promise, reason) => {
13+
console.log({ multipleResolves: { type, promise, reason } });
14+
});
15+
16+
sum(7, 3)
17+
.then(res1 => {
18+
console.log({ res1 });
19+
});

0 commit comments

Comments
 (0)