File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
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
+ } else {
7
+ reject ( new Error ( 'a and b should be numbers' ) ) ;
8
+ }
9
+ } ) ;
10
+
11
+ process . on ( 'warning' , warning => {
12
+ console . log ( { warning } ) ;
13
+ } ) ;
14
+
15
+ sum ( 7 , 'A' )
16
+ . then ( data => {
17
+ console . log ( data ) ;
18
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } else {
7
+ reject ( new Error ( 'a and b should be numbers' ) ) ;
8
+ }
9
+ } ) ;
10
+
11
+ process . on ( 'unhandledRejection' , ( reason , promise ) => {
12
+ console . log ( { unhandledRejection : { reason, promise } } ) ;
13
+ } ) ;
14
+
15
+ sum ( 7 , 'A' )
16
+ . then ( data => {
17
+ console . log ( { data } ) ;
18
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } else {
7
+ reject ( new Error ( 'a and b should be numbers' ) ) ;
8
+ }
9
+ } ) ;
10
+
11
+ process . on ( 'unhandledRejection' , ( reason , promise ) => {
12
+ console . log ( { unhandledRejection : { reason, promise } } ) ;
13
+ } ) ;
14
+
15
+ process . on ( 'rejectionHandled' , promise => {
16
+ console . log ( { rejectionHandled : { promise } } ) ;
17
+ } ) ;
18
+
19
+ const p1 = sum ( 7 , 'A' )
20
+ . then ( data => {
21
+ console . log ( data ) ;
22
+ } ) ;
23
+
24
+ //p1.catch(err => {
25
+ // console.log({ catch1: err });
26
+ //});
27
+
28
+ setTimeout ( ( ) => {
29
+ p1 . catch ( err => {
30
+ console . log ( { catch2 : err } ) ;
31
+ } ) ;
32
+ } , 0 ) ;
You can’t perform that action at this time.
0 commit comments