File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-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
+ sum ( 7 , 'A' )
12
+ . then (
13
+ data => {
14
+ console . log ( { data } ) ;
15
+ } ,
16
+ err => {
17
+ console . log ( { messageThen : err . message } ) ;
18
+ }
19
+ )
20
+ . catch ( err => {
21
+ console . log ( { messageCatch : err . message } ) ;
22
+ } ) ;
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
+ sum ( 7 , 'A' )
12
+ . then ( data => {
13
+ console . log ( { data } ) ;
14
+ } )
15
+ . catch ( err => {
16
+ console . log ( { messageCatch : err . message } ) ;
17
+ } )
18
+ . finally ( ( ) => {
19
+ console . log ( 'finally' ) ;
20
+ } ) ;
You can’t perform that action at this time.
0 commit comments