Skip to content

Commit 165c20b

Browse files
committed
Add callback in dispose
1 parent a2b5dba commit 165c20b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/postman-sandbox-fleet.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,24 @@ class PostmanSandboxFleet {
159159
/**
160160
* Dispose off all initialized sandbox instances from the fleet
161161
*
162+
* @param {Function} [callback] -
162163
* @returns {void}
163164
*/
164-
disposeAll () {
165+
disposeAll (callback) {
166+
let disposedCount = 0;
167+
168+
if (typeof callback !== 'function') {
169+
callback = _.noop;
170+
}
171+
165172
this.fleet.forEach((context, templateName) => {
166-
context.dispose();
173+
context.dispose(() => {
174+
this.fleet.delete(templateName);
167175

168-
this.fleet.delete(templateName);
176+
if (++disposedCount === this.fleet.size) {
177+
return callback();
178+
}
179+
});
169180
});
170181
}
171182
}

lib/postman-sandbox.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class PostmanSandbox extends UniversalVM {
132132
});
133133
}
134134

135-
dispose () {
135+
dispose (callback) {
136136
this.once('dispose', () => {
137137
_.forEach(this._executing, (irq, id) => {
138138
irq && clearTimeout(irq);
@@ -149,6 +149,8 @@ class PostmanSandbox extends UniversalVM {
149149
this.removeAllListeners(ASSERTION_EVENT_NAME);
150150
this.removeAllListeners(ERROR_EVENT_NAME);
151151
this.disconnect();
152+
153+
typeof callback === 'function' && callback();
152154
});
153155

154156
this.dispatch('dispose');

0 commit comments

Comments
 (0)