Last active
August 29, 2015 14:19
-
-
Save reyramos/47fa309a826c1bb9f875 to your computer and use it in GitHub Desktop.
angular Controller example calling 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
| 'use strict'; | |
| /** | |
| * # Application | |
| * | |
| * Core Application controller that includes functions used before we kickStart the Application | |
| * The functions store within this files live outside of the ngView and are used as global function | |
| */ | |
| angular.module('app').controller( | |
| 'webworkerController', [ | |
| '$rootScope', | |
| '$scope', | |
| '$timeout', | |
| '$log', | |
| '$window', | |
| 'Worker', | |
| function ($rootScope, $scope, $timeout, $log, $window, Worker) | |
| { | |
| var worker = new Worker({ | |
| url: 'js/workers/doWork2.js' //set the path of the webworker | |
| }) | |
| worker.then(function (worker) { | |
| $scope.sayHI = function () { | |
| worker.postMessage({ | |
| 'cmd': 'start', | |
| 'msg': 'Hi' | |
| }); | |
| } | |
| $scope.stop = function () { | |
| worker.postMessage({ | |
| 'cmd': 'stop', | |
| 'msg': 'Bye' | |
| }); | |
| worker.end(); | |
| } | |
| $scope.unknownCmd = function () { | |
| worker.postMessage({ | |
| 'cmd': 'foobard', | |
| 'msg': '???' | |
| }); | |
| } | |
| worker.onmessage = function (e) { | |
| document.getElementById('result').textContent = e.data; | |
| } | |
| worker.start() | |
| }, function () { | |
| console.info("ERROR") | |
| }) | |
| } | |
| ] | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment