Created
February 12, 2010 18:55
-
-
Save youpy/302855 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var worker = {}; | |
| worker.start = function(uri, data) { | |
| var deferred = new Deferred(); | |
| var worker = new Worker(uri); | |
| worker.onmessage = function(event) { deferred.call(event); }; | |
| worker.onerror = function(event) { deferred.fail(event); }; | |
| worker.postMessage(data); | |
| deferred.canceller = function() { worker.terminate() }; | |
| return deferred; | |
| } | |
| worker.start("hello_worker.js", "world").next(function(event) { | |
| alert(event.data); | |
| }); | |
| // hello_worker.js | |
| // | |
| // onmessage = function(event) { | |
| // postMessage("hello " + event.data); | |
| // }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment