Skip to content

Commit a3db9e5

Browse files
author
Anand Thakker
committed
Revert revokeObjectURL; simply attach objectURL
Reverts the change introduced by #16 Addresses #26
1 parent cfab36c commit a3db9e5

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

example/main.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
var work = require('../');
22

33
var w = work(require('./worker.js'));
4+
5+
var first = true;
46
w.addEventListener('message', function (ev) {
7+
if (first) {
8+
// revoke the Object URL that was used to create this worker, so as
9+
// not to leak it
10+
URL.revokeObjectURL(w.objectURL);
11+
first = false;
12+
}
513
console.log(ev.data);
614
});
715

index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ module.exports = function (fn, options) {
6262
if (options && options.bare) { return blob; }
6363
var workerUrl = URL.createObjectURL(blob);
6464
var worker = new Worker(workerUrl);
65-
if (typeof URL.revokeObjectURL == "function") {
66-
URL.revokeObjectURL(workerUrl);
67-
}
65+
worker.objectURL = workerUrl;
6866
return worker;
6967
};

readme.markdown

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ part. It is necessary for the main code to `require()` the worker code to fetch
7070
the module reference and load `modulePath`'s dependency graph into the bundle
7171
output.
7272

73+
## Worker.objectURL
74+
75+
The worker `w` returned by `webworkify` has the property `objectURL` attached.
76+
`w.objectURL` refers to the Object URL that was used to pass the module's source
77+
to the worker, and can be cleaned up using `URL.revokeObjectURL()`. (See [example](https://github.com/substack/webworkify/blob/master/example/main.js))
78+
7379
# install
7480

7581
With [npm](https://npmjs.org) do:

0 commit comments

Comments
 (0)