@@ -400,9 +400,13 @@ func (p *processor) Spawn(parent *Event, nodes []*insaneJSON.Node) {
400
400
nextActionIdx := parent .action + 1
401
401
402
402
wg := & sync.WaitGroup {}
403
- results := make (chan * Event )
403
+ results := make ([]* Event , len (nodes ))
404
+ resultsChan := make (chan struct {
405
+ index int
406
+ child * Event
407
+ }, len (nodes ))
404
408
405
- for _ , node := range nodes {
409
+ for i , node := range nodes {
406
410
// we can't reuse parent event (using insaneJSON.Root{Node: child}
407
411
// because of nil decoder
408
412
child := & Event {
@@ -415,21 +419,28 @@ func (p *processor) Spawn(parent *Event, nodes []*insaneJSON.Node) {
415
419
child .action = nextActionIdx
416
420
417
421
wg .Add (1 )
418
- go func (child * Event ) {
422
+ go func (i int , child * Event ) {
419
423
defer wg .Done ()
420
424
ok , _ := p .doActions (child )
421
425
if ok {
422
- results <- child
426
+ resultsChan <- struct {
427
+ index int
428
+ child * Event
429
+ }{index : i , child : child }
423
430
}
424
- }(child )
431
+ }(i , child )
425
432
}
426
433
427
434
go func () {
428
435
wg .Wait ()
429
- close (results )
436
+ close (resultsChan )
430
437
}()
431
438
432
- for child := range results {
439
+ for result := range resultsChan {
440
+ results [result .index ] = result .child
441
+ }
442
+
443
+ for _ , child := range results {
433
444
child .stage = eventStageOutput
434
445
p .output .Out (child )
435
446
child .Root .ReleaseMem ()
0 commit comments