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
+ function * genFn ( ) {
4
+ yield 10 ;
5
+ yield 20 ;
6
+ yield 30 ;
7
+ }
8
+
9
+ {
10
+ const g = genFn ( ) ;
11
+ const val1 = g . next ( ) ;
12
+ const val2 = g . next ( ) ;
13
+ const val3 = g . next ( ) ;
14
+ const val4 = g . return ( 40 ) ;
15
+ console . log ( { val1, val2, val3, val4 } ) ;
16
+ }
17
+
18
+ {
19
+ const g = genFn ( ) ;
20
+ const val1 = g . next ( ) ;
21
+ const val2 = g . return ( 40 ) ;
22
+ const val3 = g . next ( ) ;
23
+ const val4 = g . return ( 50 ) ;
24
+ console . log ( { val1, val2, val3, val4 } ) ;
25
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ function * genFn ( ) {
4
+ yield 10 ;
5
+ yield 20 ;
6
+ yield 30 ;
7
+ }
8
+
9
+ try {
10
+ const g = genFn ( ) ;
11
+ const val1 = g . next ( ) ;
12
+ const val2 = g . next ( ) ;
13
+ const val3 = g . next ( ) ;
14
+ const val4 = g . throw ( 'Error message' ) ;
15
+ console . log ( { val1, val2, val3, val4 } ) ;
16
+ } catch ( err ) {
17
+ console . error ( err ) ;
18
+ }
19
+
20
+ try {
21
+ const g = genFn ( ) ;
22
+ const val1 = g . next ( ) ;
23
+ const val2 = g . throw ( 'Error message 1' ) ;
24
+ const val3 = g . next ( ) ;
25
+ const val4 = g . throw ( 'Error message 2' ) ;
26
+ console . log ( { val1, val2, val3, val4 } ) ;
27
+ } catch ( err ) {
28
+ console . error ( err ) ;
29
+ }
You can’t perform that action at this time.
0 commit comments