File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const sum = async ( a , b ) => {
4+ if ( typeof a === 'number' && typeof b === 'number' ) {
5+ return a + b ;
6+ }
7+ throw new Error ( 'a and b should be numbers' ) ;
8+ } ;
9+
10+ ( async ( ) => {
11+
12+ const x = 2 ;
13+ const y = 3 ;
14+ const total = await sum ( x , y ) . catch ( ( err ) => {
15+ console . error ( { x, y, err } ) ;
16+ return NaN ;
17+ } ) ;
18+ console . log ( { x, y, total } ) ;
19+
20+ const z = 7 ;
21+ const c = 'A' ;
22+ const res = await sum ( z , c ) . catch ( ( err ) => {
23+ console . error ( { z, c, err } ) ;
24+ return NaN ;
25+ } ) ;
26+ console . log ( { z, c, res } ) ;
27+
28+ } ) ( ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const sum = async ( a , b ) => {
4+ if ( typeof a === 'number' && typeof b === 'number' ) {
5+ return a + b ;
6+ }
7+ throw new Error ( 'a and b should be numbers' ) ;
8+ } ;
9+
10+ ( async ( ) => {
11+
12+ const data = [
13+ [ 2 , 3 ] ,
14+ [ 7 , 'A' ] ,
15+ ] ;
16+
17+ const [ total , result ] = await Promise . all (
18+ data . map ( ( args ) =>
19+ sum ( ...args ) . catch ( ( err ) => {
20+ console . error ( err ) ;
21+ } )
22+ )
23+ ) ;
24+ console . log ( { total, result } ) ;
25+
26+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments