Skip to content

Commit b271c9f

Browse files
committed
Fix process not exiting - add method to clear resources
1 parent f124f4d commit b271c9f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

promises/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async function initWorker() {
2222
worker.postMessage({ id, isClass, self, method, args });
2323
});
2424
},
25+
terminate: () => worker.terminate(),
2526
};
2627
resolve(wrappedWorker);
2728
}
@@ -31,6 +32,14 @@ async function initWorker() {
3132
return workerPromise;
3233
}
3334

35+
async function clearResources() {
36+
if (workerPromise) {
37+
const worker = await workerPromise;
38+
workerPromise = null;
39+
await worker.terminate();
40+
}
41+
}
42+
3443
function proxify(worker, res) {
3544
return new Proxy(res, {
3645
get(obj, method) {
@@ -64,3 +73,4 @@ exports.Wallet = wrapClass("Wallet");
6473
exports.dropOnline = wrapMethod("dropOnline");
6574
exports.generateKeys = wrapMethod("generateKeys");
6675
exports.restoreKeys = wrapMethod("restoreKeys");
76+
exports.clearResources = clearResources;

0 commit comments

Comments
 (0)