Created
April 23, 2014 18:47
-
-
Save subtubes-io/11227823 to your computer and use it in GitHub Desktop.
AngularJS Webworker
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
(function () { | |
"use strict"; | |
angular.module("exampleApp") | |
.factory("WebWorks", ["$q", function ($q) { | |
var worker = new Worker('scripts/workers/doWork.js'); | |
var defer; | |
worker.addEventListener('message', function(e) { | |
defer.resolve(e.data); | |
}, false); | |
return { | |
doWork : function(myData){ | |
defer = $q.defer(); | |
worker.postMessage(myData); // Send data to our worker. | |
return defer.promise; | |
} | |
}; | |
}]) | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment