File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ const STATE_EXIT = 3;
99
1010let state = STATE_INIT ;
1111
12- ( async ( ) => {
12+ const main = async ( ) => {
1313 for await ( const chunk of process . stdin ) {
1414 console . log ( { chunk } ) ;
1515 switch ( state ) {
@@ -30,4 +30,6 @@ let state = STATE_INIT;
3030 process . exit ( 0 ) ;
3131 }
3232 }
33- } ) ( ) ;
33+ } ;
34+
35+ main ( ) ;
Original file line number Diff line number Diff line change 33const TIME_STEP = 500 ;
44
55class StateMachine {
6+ static STATE = {
7+ INIT : 0 ,
8+ WORK : 1 ,
9+ FIN : 2 ,
10+ EXIT : 3 ,
11+ } ;
12+
613 constructor ( ) {
714 this . state = StateMachine . STATE . INIT ;
815 this . timer = setInterval ( ( ) => {
@@ -26,14 +33,8 @@ class StateMachine {
2633 }
2734}
2835
29- StateMachine . STATE = {
30- INIT : 0 ,
31- WORK : 1 ,
32- FIN : 2 ,
33- EXIT : 3 ,
34- } ;
35-
3636const sm = new StateMachine ( ) ;
37+
3738process . on ( 'SIGINT' , ( ) => {
3839 sm . state = StateMachine . STATE . FIN ;
3940} ) ;
You can’t perform that action at this time.
0 commit comments