Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes issue #4.

Don't assume that the worker script has loaded.
  • Loading branch information...
commit 27986c2cb045bc1c5b0be5a0b8f234cff7364e41 1 parent 471adb4
@nmrugg authored
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/lzma.js
View
13 src/lzma.js
@@ -28,7 +28,7 @@ if (!Worker) {
var script_tag = document.createElement("script");
script_tag.type ="text/javascript";
script_tag.src = path;
- document.getElementsByTagName('head')[0].appendChild(script_tag);
+ document.getElementsByTagName("head")[0].appendChild(script_tag);
};
}
@@ -37,12 +37,17 @@ if (!Worker) {
/// This is the function that the main script calls to post a message to the "worker."
return_object.postMessage = function (message) {
- /// Delay the call just in case the "worker" script has not had time to load.
- setTimeout(function () {
+ /// Has the worker script loaded yet?
+ if (global_var.onmessage) {
/// Call the global onmessage() created by the "worker."
///NOTE: Wrap the message in an object.
global_var.onmessage({data: message});
- }, 10);
+ } else {
+ /// Since the script has not yet loaded, wait a moment, and then retry.
+ setTimeout(function () {
+ return_object.postMessage(message);
+ }, 50);
+ }
};
/// Create a global postMessage() function for the "worker" to call.
Please sign in to comment.
Something went wrong with that request. Please try again.