@@ -6,6 +6,8 @@ const _ = require('lodash'),
6
6
7
7
TO_WAIT_BUFFER = 500 , // time to wait for sandbox to declare timeout
8
8
CONSOLE_EVENT_NAME = 'execution.console' ,
9
+ ASSERTION_EVENT_NAME = 'execution.assertion' ,
10
+ ERROR_EVENT_NAME = 'execution.error' ,
9
11
EXECUTION_TIMEOUT_ERROR_MESSAGE = 'sandbox not responding' ,
10
12
BRIDGE_DISCONNECTING_ERROR_MESSAGE = 'sandbox: execution interrupted, bridge disconnecting.' ;
11
13
@@ -131,19 +133,25 @@ class PostmanSandbox extends UniversalVM {
131
133
}
132
134
133
135
dispose ( ) {
134
- _ . forEach ( this . _executing , ( irq , id ) => {
135
- irq && clearTimeout ( irq ) ;
136
+ this . once ( 'dispose' , ( ) => {
137
+ _ . forEach ( this . _executing , ( irq , id ) => {
138
+ irq && clearTimeout ( irq ) ;
136
139
137
- // send an abort event to the sandbox so that it can do cleanups
138
- this . dispatch ( 'execution.abort.' + id ) ;
140
+ // send an abort event to the sandbox so that it can do cleanups
141
+ this . dispatch ( 'execution.abort.' + id ) ;
139
142
140
- // even though sandbox could bubble the result event upon receiving abort, that would reduce
141
- // stability of the system in case sandbox was unresponsive.
142
- this . emit ( 'execution.result.' + id , new Error ( BRIDGE_DISCONNECTING_ERROR_MESSAGE ) ) ;
143
+ // even though sandbox could bubble the result event upon receiving abort, that would reduce
144
+ // stability of the system in case sandbox was unresponsive.
145
+ this . emit ( 'execution.result.' + id , new Error ( BRIDGE_DISCONNECTING_ERROR_MESSAGE ) ) ;
146
+ } ) ;
147
+
148
+ this . removeAllListeners ( CONSOLE_EVENT_NAME ) ;
149
+ this . removeAllListeners ( ASSERTION_EVENT_NAME ) ;
150
+ this . removeAllListeners ( ERROR_EVENT_NAME ) ;
151
+ this . disconnect ( ) ;
143
152
} ) ;
144
153
145
- this . removeAllListeners ( CONSOLE_EVENT_NAME ) ;
146
- this . disconnect ( ) ;
154
+ this . dispatch ( 'dispose' ) ;
147
155
}
148
156
}
149
157
0 commit comments