File tree 1 file changed +27
-4
lines changed 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ const beforeExitSubscribers = new Set ( ) ;
4
+ const beforeExitHandler = ( ) => {
5
+ for ( const subscriber of beforeExitSubscribers ) {
6
+ subscriber ( ) ;
7
+ }
8
+ } ;
9
+ const onBeforeExit = subscriber => {
10
+ if ( beforeExitSubscribers . size === 0 ) {
11
+ // Only listen for the event once, no matter how many Sequences are run
12
+ // concurrently.
13
+ process . on ( 'beforeExit' , beforeExitHandler ) ;
14
+ }
15
+
16
+ beforeExitSubscribers . add ( subscriber ) ;
17
+ return {
18
+ dispose ( ) {
19
+ beforeExitSubscribers . delete ( subscriber ) ;
20
+ if ( beforeExitSubscribers . size === 0 ) {
21
+ process . removeListener ( 'beforeExit' , beforeExitHandler ) ;
22
+ }
23
+ }
24
+ } ;
25
+ } ;
26
+
3
27
class Sequence {
4
28
constructor ( runnables , bail ) {
5
29
if ( ! Array . isArray ( runnables ) ) {
@@ -14,16 +38,15 @@ class Sequence {
14
38
const iterator = this . runnables [ Symbol . iterator ] ( ) ;
15
39
16
40
let activeRunnable ;
17
- const onBeforeExit = ( ) => {
41
+ const beforeExit = onBeforeExit ( ( ) => {
18
42
if ( activeRunnable . finishDueToInactivity ) {
19
43
activeRunnable . finishDueToInactivity ( ) ;
20
44
}
21
- } ;
22
- process . on ( 'beforeExit' , onBeforeExit ) ;
45
+ } ) ;
23
46
24
47
let allPassed = true ;
25
48
const finish = ( ) => {
26
- process . removeListener ( 'beforeExit' , onBeforeExit ) ;
49
+ beforeExit . dispose ( ) ;
27
50
return allPassed ;
28
51
} ;
29
52
You can’t perform that action at this time.
0 commit comments