File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change 8989 }
9090 } ;
9191
92+ Thread . prototype . _spawnWorker = function ( cb ) {
93+ var wrk = new Worker ( this . options . path ) ;
94+ wrk . postMessage ( Thread . getWorkerSource ( cb ) ) ;
95+
96+ return wrk ;
97+ } ;
98+
9299 Thread . prototype . spawn = function ( cb ) {
93100 var that = this ;
94101 var newOp = new Operation ( ) ;
95102 this . operation . then ( function ( ) {
96- var wrk = new Worker ( that . options . path ) ;
97- wrk . postMessage ( Thread . getWorkerSource ( cb ) ) ;
103+ var wrk = that . _spawnWorker ( cb ) ;
98104 wrk . onmessage = function ( msg ) {
99105 wrk . terminate ( ) ;
100106 that . data = msg . data ;
108114
109115 Thread . prototype . _spawnMapWorker = function ( i , cb , done ) {
110116 var that = this ;
111- var wrk = new Worker ( that . options . path ) ;
112- wrk . postMessage ( Thread . getWorkerSource ( cb ) ) ;
117+ var wrk = that . _spawnWorker ( cb ) ;
113118 wrk . onmessage = function ( msg ) {
114119 wrk . terminate ( ) ;
115120 that . data [ i ] = msg . data ;
146151
147152 Thread . prototype . _spawnReduceWorker = function ( data , cb , done ) {
148153 var that = this ;
149- var wrk = new Worker ( that . options . path ) ;
150- wrk . postMessage ( Thread . getWorkerSource ( cb ) ) ;
154+ var wrk = that . _spawnWorker ( cb ) ;
151155 wrk . onmessage = function ( msg ) {
152156 wrk . terminate ( ) ;
153157 that . data [ that . data . length ] = msg . data ;
You can’t perform that action at this time.
0 commit comments