@@ -7,7 +7,8 @@ var $getStackDepth = function() {
7
7
return $stackDepthOffset + err . stack . split ( "\n" ) . length ;
8
8
} ;
9
9
10
- var $panicStackDepth = null , $panicValue ;
10
+ var $panicStackDepth = null ,
11
+ $panicValue ;
11
12
var $callDeferred = function ( deferred , jsErr , fromPanic ) {
12
13
if ( ! fromPanic && deferred !== null && deferred . index >= $curGoroutine . deferStack . length ) {
13
14
throw jsErr ;
@@ -106,10 +107,20 @@ var $recover = function() {
106
107
$panicStackDepth = null ;
107
108
return $panicValue ;
108
109
} ;
109
- var $throw = function ( err ) { throw err ; } ;
110
+ var $throw = function ( err ) {
111
+ throw err ;
112
+ } ;
110
113
111
- var $noGoroutine = { asleep : false , exit : false , deferStack : [ ] , panicStack : [ ] } ;
112
- var $curGoroutine = $noGoroutine , $totalGoroutines = 0 , $awakeGoroutines = 0 , $checkForDeadlock = true ;
114
+ var $noGoroutine = {
115
+ asleep : false ,
116
+ exit : false ,
117
+ deferStack : [ ] ,
118
+ panicStack : [ ] ,
119
+ } ;
120
+ var $curGoroutine = $noGoroutine ,
121
+ $totalGoroutines = 0 ,
122
+ $awakeGoroutines = 0 ,
123
+ $checkForDeadlock = true ;
113
124
var $mainFinished = false ;
114
125
var $go = function ( fun , args ) {
115
126
$totalGoroutines ++ ;
@@ -119,7 +130,9 @@ var $go = function(fun, args) {
119
130
$curGoroutine = $goroutine ;
120
131
var r = fun . apply ( undefined , args ) ;
121
132
if ( r && r . $blk !== undefined ) {
122
- fun = function ( ) { return r . $blk ( ) ; } ;
133
+ fun = function ( ) {
134
+ return r . $blk ( ) ;
135
+ } ;
123
136
args = [ ] ;
124
137
return ;
125
138
}
@@ -130,7 +143,8 @@ var $go = function(fun, args) {
130
143
}
131
144
} finally {
132
145
$curGoroutine = $noGoroutine ;
133
- if ( $goroutine . exit ) { /* also set by runtime.Goexit() */
146
+ if ( $goroutine . exit ) {
147
+ /* also set by runtime.Goexit() */
134
148
$totalGoroutines -- ;
135
149
$goroutine . asleep = true ;
136
150
}
@@ -219,7 +233,7 @@ var $send = function(chan, value) {
219
233
if ( closedDuringSend ) {
220
234
$throwRuntimeError ( "send on closed channel" ) ;
221
235
}
222
- }
236
+ } ,
223
237
} ;
224
238
} ;
225
239
var $recv = function ( chan ) {
@@ -236,7 +250,11 @@ var $recv = function(chan) {
236
250
}
237
251
238
252
var thisGoroutine = $curGoroutine ;
239
- var f = { $blk : function ( ) { return this . value ; } } ;
253
+ var f = {
254
+ $blk : function ( ) {
255
+ return this . value ;
256
+ } ,
257
+ } ;
240
258
var queueEntry = function ( v ) {
241
259
f . value = v ;
242
260
$schedule ( thisGoroutine ) ;
@@ -272,22 +290,22 @@ var $select = function(comms) {
272
290
var comm = comms [ i ] ;
273
291
var chan = comm [ 0 ] ;
274
292
switch ( comm . length ) {
275
- case 0 : /* default */
276
- selection = i ;
277
- break ;
278
- case 1 : /* recv */
279
- if ( chan . $sendQueue . length !== 0 || chan . $buffer . length !== 0 || chan . $closed ) {
280
- ready . push ( i ) ;
281
- }
282
- break ;
283
- case 2 : /* send */
284
- if ( chan . $closed ) {
285
- $throwRuntimeError ( "send on closed channel" ) ;
286
- }
287
- if ( chan . $recvQueue . length !== 0 || chan . $buffer . length < chan . $capacity ) {
288
- ready . push ( i ) ;
289
- }
290
- break ;
293
+ case 0 /* default */ :
294
+ selection = i ;
295
+ break ;
296
+ case 1 /* recv */ :
297
+ if ( chan . $sendQueue . length !== 0 || chan . $buffer . length !== 0 || chan . $closed ) {
298
+ ready . push ( i ) ;
299
+ }
300
+ break ;
301
+ case 2 /* send */ :
302
+ if ( chan . $closed ) {
303
+ $throwRuntimeError ( "send on closed channel" ) ;
304
+ }
305
+ if ( chan . $recvQueue . length !== 0 || chan . $buffer . length < chan . $capacity ) {
306
+ ready . push ( i ) ;
307
+ }
308
+ break ;
291
309
}
292
310
}
293
311
@@ -297,19 +315,23 @@ var $select = function(comms) {
297
315
if ( selection !== - 1 ) {
298
316
var comm = comms [ selection ] ;
299
317
switch ( comm . length ) {
300
- case 0 : /* default */
301
- return [ selection ] ;
302
- case 1 : /* recv */
303
- return [ selection , $recv ( comm [ 0 ] ) ] ;
304
- case 2 : /* send */
305
- $send ( comm [ 0 ] , comm [ 1 ] ) ;
306
- return [ selection ] ;
318
+ case 0 /* default */ :
319
+ return [ selection ] ;
320
+ case 1 /* recv */ :
321
+ return [ selection , $recv ( comm [ 0 ] ) ] ;
322
+ case 2 /* send */ :
323
+ $send ( comm [ 0 ] , comm [ 1 ] ) ;
324
+ return [ selection ] ;
307
325
}
308
326
}
309
327
310
328
var entries = [ ] ;
311
329
var thisGoroutine = $curGoroutine ;
312
- var f = { $blk : function ( ) { return this . selection ; } } ;
330
+ var f = {
331
+ $blk : function ( ) {
332
+ return this . selection ;
333
+ } ,
334
+ } ;
313
335
var removeFromQueues = function ( ) {
314
336
for ( var i = 0 ; i < entries . length ; i ++ ) {
315
337
var entry = entries [ i ] ;
@@ -324,28 +346,28 @@ var $select = function(comms) {
324
346
( function ( i ) {
325
347
var comm = comms [ i ] ;
326
348
switch ( comm . length ) {
327
- case 1 : /* recv */
328
- var queueEntry = function ( value ) {
329
- f . selection = [ i , value ] ;
330
- removeFromQueues ( ) ;
331
- $schedule ( thisGoroutine ) ;
332
- } ;
333
- entries . push ( [ comm [ 0 ] . $recvQueue , queueEntry ] ) ;
334
- comm [ 0 ] . $recvQueue . push ( queueEntry ) ;
335
- break ;
336
- case 2 : /* send */
337
- var queueEntry = function ( ) {
338
- if ( comm [ 0 ] . $closed ) {
339
- $throwRuntimeError ( "send on closed channel" ) ;
340
- }
341
- f . selection = [ i ] ;
342
- removeFromQueues ( ) ;
343
- $schedule ( thisGoroutine ) ;
344
- return comm [ 1 ] ;
345
- } ;
346
- entries . push ( [ comm [ 0 ] . $sendQueue , queueEntry ] ) ;
347
- comm [ 0 ] . $sendQueue . push ( queueEntry ) ;
348
- break ;
349
+ case 1 /* recv */ :
350
+ var queueEntry = function ( value ) {
351
+ f . selection = [ i , value ] ;
352
+ removeFromQueues ( ) ;
353
+ $schedule ( thisGoroutine ) ;
354
+ } ;
355
+ entries . push ( [ comm [ 0 ] . $recvQueue , queueEntry ] ) ;
356
+ comm [ 0 ] . $recvQueue . push ( queueEntry ) ;
357
+ break ;
358
+ case 2 /* send */ :
359
+ var queueEntry = function ( ) {
360
+ if ( comm [ 0 ] . $closed ) {
361
+ $throwRuntimeError ( "send on closed channel" ) ;
362
+ }
363
+ f . selection = [ i ] ;
364
+ removeFromQueues ( ) ;
365
+ $schedule ( thisGoroutine ) ;
366
+ return comm [ 1 ] ;
367
+ } ;
368
+ entries . push ( [ comm [ 0 ] . $sendQueue , queueEntry ] ) ;
369
+ comm [ 0 ] . $sendQueue . push ( queueEntry ) ;
370
+ break ;
349
371
}
350
372
} ) ( i ) ;
351
373
}
0 commit comments