File tree Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22
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+
327class Sequence {
428 constructor ( runnables , bail ) {
529 if ( ! Array . isArray ( runnables ) ) {
@@ -14,16 +38,15 @@ class Sequence {
1438 const iterator = this . runnables [ Symbol . iterator ] ( ) ;
1539
1640 let activeRunnable ;
17- const onBeforeExit = ( ) => {
41+ const beforeExit = onBeforeExit ( ( ) => {
1842 if ( activeRunnable . finishDueToInactivity ) {
1943 activeRunnable . finishDueToInactivity ( ) ;
2044 }
21- } ;
22- process . on ( 'beforeExit' , onBeforeExit ) ;
45+ } ) ;
2346
2447 let allPassed = true ;
2548 const finish = ( ) => {
26- process . removeListener ( 'beforeExit' , onBeforeExit ) ;
49+ beforeExit . dispose ( ) ;
2750 return allPassed ;
2851 } ;
2952
You can’t perform that action at this time.
0 commit comments