File tree Expand file tree Collapse file tree 3 files changed +20
-16
lines changed
Expand file tree Collapse file tree 3 files changed +20
-16
lines changed Original file line number Diff line number Diff line change 3535 this . _resolved = 2 ;
3636 this . _result = err ;
3737
38- for ( var i = 0 ; i < this . _errCallbacks . length ; ++ i ) {
39- this . _errCallbacks [ i ] ( res ) ;
38+ for ( var iE = 0 ; iE < this . _errCallbacks . length ; ++ iE ) {
39+ this . _errCallbacks [ iE ] ( res ) ;
4040 }
4141 }
4242
9595 this . operation . then ( function ( ) {
9696 var wrk = new Worker ( that . options . path ) ;
9797 wrk . postMessage ( Thread . getWorkerSource ( cb ) ) ;
98- wrk . postMessage ( that . data ) ;
9998 wrk . onmessage = function ( msg ) {
10099 wrk . terminate ( ) ;
101100 that . data = msg . data ;
102101 newOp . resolve ( null , that . data ) ;
103102 } ;
103+ wrk . postMessage ( that . data ) ;
104104 } ) ;
105105 this . operation = newOp ;
106106 return this ;
110110 var that = this ;
111111 var wrk = new Worker ( that . options . path ) ;
112112 wrk . postMessage ( Thread . getWorkerSource ( cb ) ) ;
113- wrk . postMessage ( that . data [ i ] ) ;
114113 wrk . onmessage = function ( msg ) {
115114 wrk . terminate ( ) ;
116115 that . data [ i ] = msg . data ;
117116 done ( ) ;
118117 } ;
118+ wrk . postMessage ( that . data [ i ] ) ;
119119 } ;
120120
121121 Thread . prototype . map = function ( cb ) {
148148 var that = this ;
149149 var wrk = new Worker ( that . options . path ) ;
150150 wrk . postMessage ( Thread . getWorkerSource ( cb ) ) ;
151- wrk . postMessage ( data ) ;
152151 wrk . onmessage = function ( msg ) {
153152 wrk . terminate ( ) ;
154153 that . data [ that . data . length ] = msg . data ;
155154 done ( ) ;
156155 } ;
156+ wrk . postMessage ( data ) ;
157157 } ;
158158
159159 Thread . prototype . reduce = function ( cb ) {
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ describe('eval.js', function () {
88
99 it ( 'should eval the given code' , function ( ) {
1010 var wrk = new Worker ( __dirname + '/../lib/eval.js' ) ;
11- wrk . postMessage ( 'process.send(JSON.stringify("abc"))' ) ;
1211
1312 var result = null ;
1413 var done = false ;
@@ -18,6 +17,7 @@ describe('eval.js', function () {
1817 done = true ;
1918 wrk . terminate ( ) ;
2019 } ;
20+ wrk . postMessage ( 'process.send(JSON.stringify("abc"))' ) ;
2121 } ) ;
2222
2323 waitsFor ( function ( ) {
Original file line number Diff line number Diff line change 1414 var p2 = new Thread ( [ 1000 , 2000 , 3000 ] ) ;
1515
1616 var start = Date . now ( ) ;
17- var start2 = Date . now ( ) ;
18-
1917 var time = null ;
20- var time2 = null ;
2118
2219 runs ( function ( ) {
2320 p . spawn ( function ( data ) {
2421 for ( var i = 0 ; i < data . length ; ++ i ) {
2522 var n = data [ i ] ;
26- var i = 0 ;
27- while ( ++ i < n * n ) { }
28- data [ i ] = i ;
23+ var square ;
24+ for ( square = 0 ; square < n * n ; ++ square ) { }
25+ data [ i ] = square ;
2926 }
3027 return data ;
3128 } ) . then ( function ( data ) {
3229 time = Date . now ( ) - start ;
33- result = data ;
3430 } ) ;
31+ } ) ;
32+
33+ waitsFor ( function ( ) {
34+ return time !== null ;
35+ } , "Sequential should finish" , 5000 ) ;
3536
37+ var start2 = Date . now ( ) ;
38+ var time2 = null ;
39+
40+ runs ( function ( ) {
3641 p2 . map ( slowSquare ) . then ( function ( data ) {
3742 time2 = Date . now ( ) - start2 ;
38- result = data ;
3943 } ) ;
4044 } ) ;
4145
4246 waitsFor ( function ( ) {
43- return time != null && time2 != null ;
44- } , "it should finish" , 5000 ) ;
47+ return time2 != = null ;
48+ } , "Parallel should finish" , 5000 ) ;
4549
4650 runs ( function ( ) {
4751 expect ( time2 ) . toBeLessThan ( time / cpus ) ;
You can’t perform that action at this time.
0 commit comments