Terminate workers in openpgp.destroyWorker()

This commit is contained in:
Daniel Huigens 2020-01-15 13:25:59 +01:00
parent 94a04eaa5c
commit 6ae6012786
2 changed files with 8 additions and 3 deletions

View File

@ -90,8 +90,11 @@ export function getWorker() {
* Cleanup the current instance of the web worker. * Cleanup the current instance of the web worker.
*/ */
export function destroyWorker() { export function destroyWorker() {
if (asyncProxy) {
asyncProxy.terminate();
asyncProxy = undefined; asyncProxy = undefined;
} }
}
////////////////////// //////////////////////

View File

@ -446,7 +446,8 @@ describe('OpenPGP.js public api tests', function() {
it('should work', async function() { it('should work', async function() {
const workerStub = { const workerStub = {
postMessage: function() {} postMessage: function() {},
terminate: function() {}
}; };
await Promise.all([ await Promise.all([
openpgp.initWorker({ openpgp.initWorker({
@ -600,7 +601,8 @@ describe('OpenPGP.js public api tests', function() {
it('should delegate to async proxy', async function() { it('should delegate to async proxy', async function() {
const workerStub = { const workerStub = {
postMessage: function() {} postMessage: function() {},
terminate: function() {}
}; };
await Promise.all([ await Promise.all([
openpgp.initWorker({ openpgp.initWorker({