Skip to content

Commit

Permalink
Terminate workers in openpgp.destroyWorker()
Browse files Browse the repository at this point in the history
  • Loading branch information
twiss committed Jan 15, 2020
1 parent 1462aff commit 005a3c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/openpgp.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ export function getWorker() {
* Cleanup the current instance of the web worker.
*/
export function destroyWorker() {
asyncProxy = undefined;
if (asyncProxy) {
asyncProxy.workers.forEach(worker => {
worker.terminate();
});
asyncProxy = undefined;
}
}


Expand Down
6 changes: 4 additions & 2 deletions test/general/openpgp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 005a3c3

Please sign in to comment.