Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share a single blob URL between all workers #3239

Merged
merged 1 commit into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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