File tree 2 files changed +6
-16
lines changed
2 files changed +6
-16
lines changed Original file line number Diff line number Diff line change 8
8
# dev files
9
9
.idea
10
10
11
- # Test binary, built with `go test -c`
11
+ # For test
12
+ ** /testdata
12
13
* .test
13
14
14
15
# Output of the go coverage tool, specifically when used with LiteIDE
Original file line number Diff line number Diff line change @@ -286,33 +286,21 @@ func drain(channel <-chan interface{}) {
286
286
287
287
func executeMappers (mCtx mapperContext ) {
288
288
var wg sync.WaitGroup
289
- pc := & onceChan {channel : make (chan interface {})}
290
289
defer func () {
291
- // in case panic happens when processing last item, for loop not handling it.
292
- select {
293
- case r := <- pc .channel :
294
- mCtx .panicChan .write (r )
295
- default :
296
- }
297
-
298
290
wg .Wait ()
299
291
close (mCtx .collector )
300
292
drain (mCtx .source )
301
293
}()
302
294
295
+ var failed int32
303
296
pool := make (chan struct {}, mCtx .workers )
304
297
writer := newGuardedWriter (mCtx .ctx , mCtx .collector , mCtx .doneChan )
305
- for {
298
+ for atomic . LoadInt32 ( & failed ) == 0 {
306
299
select {
307
300
case <- mCtx .ctx .Done ():
308
301
return
309
302
case <- mCtx .doneChan :
310
303
return
311
- case r := <- pc .channel :
312
- // make sure this method quit ASAP,
313
- // without this case branch, all the items from source will be consumed.
314
- mCtx .panicChan .write (r )
315
- return
316
304
case pool <- struct {}{}:
317
305
item , ok := <- mCtx .source
318
306
if ! ok {
@@ -324,7 +312,8 @@ func executeMappers(mCtx mapperContext) {
324
312
go func () {
325
313
defer func () {
326
314
if r := recover (); r != nil {
327
- pc .write (r )
315
+ atomic .AddInt32 (& failed , 1 )
316
+ mCtx .panicChan .write (r )
328
317
}
329
318
wg .Done ()
330
319
<- pool
You can’t perform that action at this time.
0 commit comments