Skip to content

Commit

Permalink
Share a single blob URL between all workers (#3239)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh authored and mourner committed Sep 22, 2016
1 parent 56e9761 commit 594248c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
5 changes: 4 additions & 1 deletion js/util/browser/web_worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

var WebWorkify = require('webworkify');
var window = require('../window');
var workerURL = window.URL.createObjectURL(new WebWorkify(require('../../source/worker'), {bare: true}));

module.exports = function () {
return new WebWorkify(require('../../source/worker'));
return new window.Worker(workerURL);
};
2 changes: 0 additions & 2 deletions js/util/worker_pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var assert = require('assert');
var WebWorker = require('./web_worker');
var URL = require('./window').URL;

module.exports = WorkerPool;

Expand Down Expand Up @@ -37,7 +36,6 @@ WorkerPool.prototype = {
delete this.active[mapId];
if (Object.keys(this.active).length === 0) {
this.workers.forEach(function (w) {
URL.revokeObjectURL(w.objectURL);
w.terminate();
});
this.workers = null;
Expand Down
12 changes: 2 additions & 10 deletions test/js/util/worker_pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,15 @@ test('WorkerPool', function (t) {

t.test('#release', function (t) {
var workersTerminated = 0;
var objectUrlsRevoked = {};
var WorkerPool = proxyquire('../../../js/util/worker_pool', {
'../mapbox-gl': { workerCount: 4 },
'./window': {
URL: {
revokeObjectURL: function (url) { objectUrlsRevoked[url] = true; }
}
}
'../mapbox-gl': { workerCount: 4 }
});

var pool = new WorkerPool();
pool.acquire('map-1');
var workers = pool.acquire('map-2');
workers.forEach(function (w, i) {
workers.forEach(function (w) {
w.terminate = function () { workersTerminated += 1; };
w.objectURL = 'blob:worker-' + i;
});

pool.release('map-2');
Expand All @@ -50,7 +43,6 @@ test('WorkerPool', function (t) {
t.comment('terminates workers if no dispatchers are active');
pool.release('map-1');
t.equal(workersTerminated, 4);
t.equal(Object.keys(objectUrlsRevoked).length, 4);
t.notOk(pool.workers);

t.end();
Expand Down

0 comments on commit 594248c

Please sign in to comment.