Codebase list golang-github-vbauerster-mpb / 7bc9cf2
type syncTable Vladimir Bauer 3 years ago
2 changed file(s) with 27 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
2424 cancel func()
2525 }
2626
27 type syncTable [2][]chan int
2728 type extenderFunc func([]io.Reader, decor.Statistics) ([]io.Reader, error)
2829
2930 // bState is actual bar's state.
469470 }
470471 }
471472
472 func (b *Bar) wSyncTable() [][]chan int {
473 result := make(chan [][]chan int)
473 func (b *Bar) wSyncTable() syncTable {
474 result := make(chan syncTable)
474475 select {
475476 case b.operateState <- func(s *bState) { result <- s.wSyncTable() }:
476477 return <-result
558559 return io.MultiReader(bufP, bufB, bufA), nil
559560 }
560561
561 func (s *bState) wSyncTable() [][]chan int {
562 columns := make([]chan int, 0, len(s.pDecorators)+len(s.aDecorators))
563 var pCount int
564 for _, d := range s.pDecorators {
565 if ch, ok := d.Sync(); ok {
566 columns = append(columns, ch)
567 pCount++
568 }
569 }
570 var aCount int
571 for _, d := range s.aDecorators {
572 if ch, ok := d.Sync(); ok {
573 columns = append(columns, ch)
574 aCount++
575 }
576 }
577 table := make([][]chan int, 2)
578 table[0] = columns[0:pCount]
579 table[1] = columns[pCount : pCount+aCount : pCount+aCount]
562 func (s *bState) wSyncTable() (table syncTable) {
563 var count int
564 var row []chan int
565
566 for i, decorators := range [][]decor.Decorator{
567 s.pDecorators,
568 s.aDecorators,
569 } {
570 for _, d := range decorators {
571 if ch, ok := d.Sync(); ok {
572 row = append(row, ch)
573 count++
574 }
575 }
576 switch i {
577 case 0:
578 table[i] = row[0:count]
579 default:
580 table[i] = row[len(table[i-1]):count]
581 }
582 }
580583 return table
581584 }
582585
423423 for i := 0; i < s.bHeap.Len(); i++ {
424424 bar := s.bHeap[i]
425425 table := bar.wSyncTable()
426 pRow, aRow := table[0], table[1]
427
428 for i, ch := range pRow {
426
427 for i, ch := range table[0] {
429428 s.pMatrix[i] = append(s.pMatrix[i], ch)
430429 }
431430
432 for i, ch := range aRow {
431 for i, ch := range table[1] {
433432 s.aMatrix[i] = append(s.aMatrix[i], ch)
434433 }
435434 }