From 6ae60127863e51ba4b4f5e7eba2213dc866e313f Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Wed, 15 Jan 2020 13:25:59 +0100 Subject: [PATCH] Terminate workers in openpgp.destroyWorker() --- src/openpgp.js | 5 ++++- test/general/openpgp.js | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/openpgp.js b/src/openpgp.js index e84adb3e..6d6b06d4 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -90,7 +90,10 @@ export function getWorker() { * Cleanup the current instance of the web worker. */ export function destroyWorker() { - asyncProxy = undefined; + if (asyncProxy) { + asyncProxy.terminate(); + asyncProxy = undefined; + } } diff --git a/test/general/openpgp.js b/test/general/openpgp.js index 7db40b99..1490fee5 100644 --- a/test/general/openpgp.js +++ b/test/general/openpgp.js @@ -446,7 +446,8 @@ describe('OpenPGP.js public api tests', function() { it('should work', async function() { const workerStub = { - postMessage: function() {} + postMessage: function() {}, + terminate: function() {} }; await Promise.all([ openpgp.initWorker({ @@ -600,7 +601,8 @@ describe('OpenPGP.js public api tests', function() { it('should delegate to async proxy', async function() { const workerStub = { - postMessage: function() {} + postMessage: function() {}, + terminate: function() {} }; await Promise.all([ openpgp.initWorker({