github.com/tursom/GoCollections@v0.3.10/concurrent/util/Pipeline_test.go (about)

     1  /*
     2   * Copyright (c) 2022 tursom. All rights reserved.
     3   * Use of this source code is governed by a GPL-3
     4   * license that can be found in the LICENSE file.
     5   */
     6  
     7  package util
     8  
     9  import (
    10  	"fmt"
    11  	"testing"
    12  
    13  	"github.com/tursom/GoCollections/util/time"
    14  )
    15  
    16  func TestPipeline(t *testing.T) {
    17  	c := make(chan int)
    18  	r := NewPipeline(c, 4, func(t int) int {
    19  		return t * t * t * t
    20  	})
    21  
    22  	go func() {
    23  		defer close(c)
    24  		for i := 0; i < 1024; i++ {
    25  			c <- i
    26  		}
    27  		time.Sleep(time.Second)
    28  	}()
    29  
    30  	for i := range r.RCh() {
    31  		fmt.Println(i)
    32  	}
    33  }