9
9
* Main module of the application.
10
10
*/
11
11
var app = angular
12
- . module ( 'angular-workers-example' , [ 'FredrikSandell.worker-pool' ] )
12
+ . module ( 'angular-workers-example' , [ 'FredrikSandell.worker-pool' ] )
13
13
. run ( function ( WorkerService ) {
14
14
//WorkerService.setAngularUrl('../bower_components/angular/angular.js');
15
15
WorkerService . setAngularUrl ( 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js' ) ;
@@ -28,91 +28,66 @@ app.controller("myChartCtrl", function($scope,WorkerService) {
28
28
$scope . data . reply3 = 'c' ;
29
29
30
30
$scope . test = function ( arg ) {
31
-
31
+
32
32
/**
33
- // This contains the worker body.
34
- // The function must be self contained.
35
- // The function body will be converted to source and passed to the worker.
33
+ // This contains the worker body.
34
+ // The function must be self contained.
35
+ // The function body will be converted to source and passed to the worker.
36
36
// The input parameter is what will be passed to the worker when it is executed. It must be a serializable object.
37
37
// The output parameter is a promise and is what the worker will return to the main thread.
38
38
// All communication from the worker to the main thread is performed by resolving, rejecting or notifying the output promise.
39
39
// We may optionally depend on other angular services. These services can be used just as in the main thread.
40
40
// But be aware that no state changes in the angular services in the worker are propagates to the main thread. Workers run in fully isolated contexts.
41
- // All communication must be performed through the output parameter.
41
+ // All communication must be performed through the output parameter.
42
42
*/
43
43
var workerPromise = WorkerService . createAngularWorker ( [ 'input' , 'output' , '$http' , function ( input , output , $http ) {
44
-
44
+
45
45
var i = 0 ;
46
-
46
+
47
47
var callback = function ( i ) {
48
48
output . notify ( i ) ;
49
49
i ++ ;
50
50
} ;
51
-
51
+
52
52
53
53
//for (var i = 0; i < 10; i++) { callback(i); }
54
54
//var intervalID = setInterval(callback(i), 3000);
55
55
setInterval ( function ( ) { callback ( ++ i ) ; } , Math . floor ( ( Math . random ( ) * 1000 ) + 100 ) ) ;
56
-
56
+
57
57
//output.resolve(true);
58
58
//output.reject(false);
59
-
59
+
60
60
} ] ) ;
61
61
62
62
workerPromise
63
- . then ( function success ( angularWorker ) {
64
- //The input must be serializable
63
+ . then ( function success ( angularWorker ) {
64
+ //The input must be serializable
65
65
return angularWorker . run ( $scope . awesomeThings ) ;
66
66
} , function error ( reason ) {
67
-
67
+
68
68
console . log ( 'callback error' ) ;
69
69
console . log ( reason ) ;
70
-
71
- //for some reason the worker failed to initialize
72
- //not all browsers support the HTML5 tech that is required, see below.
70
+
71
+ //for some reason the worker failed to initialize
72
+ //not all browsers support the HTML5 tech that is required, see below.
73
73
} ) . then ( function success ( result ) {
74
-
74
+
75
75
console . log ( 'success' ) ;
76
76
console . log ( result ) ;
77
-
78
- //handle result
77
+
78
+ //handle result
79
79
} , function error ( reason ) {
80
80
//handle error
81
81
console . log ( 'error' ) ;
82
82
console . log ( reason ) ;
83
-
83
+
84
84
} , function notify ( update ) {
85
85
//handle update
86
-
87
- $scope . data [ 'reply' + arg ] += update + '\n' ;
86
+
87
+ $scope . data [ 'reply' + arg ] += update + '\n' ;
88
88
//console.log(arg);
89
- //console.log(update);
89
+ //console.log(update);
90
90
} ) ;
91
91
92
92
} ;
93
-
94
-
95
- } ) ;
96
-
97
-
98
- /*
99
-
100
- var app = angular.module("myApp", ['nvd3ChartDirectives']);
101
-
102
- app.controller("myChartCtrl", function($scope,$http) {
103
-
104
- $scope.data = {};
105
- $scope.data.bar = [];
106
-
107
- /*
108
- $http.get('http://localhost:8080/data?type=cheese').
109
- success(function(data, status, headers, config) {
110
- $scope.data.bar = data;
111
- }).
112
- error(function(data, status, headers, config) {
113
- console.log('error');
114
- $scope.bar = [];
115
- });
116
-
117
93
} ) ;
118
- */
0 commit comments