github.com/enetx/g@v1.0.80/examples/iter/iter_to_chan.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "sync" 7 8 "github.com/enetx/g" 9 ) 10 11 func main() { 12 ctx, cancel := context.WithCancel(context.Background()) 13 defer cancel() 14 15 jobs := g.SliceOf(1, 1, 1, 3, 4, 4, 8, 8, 9, 9). 16 Iter(). 17 // Dedup(). 18 ToChan(ctx) 19 20 // for job := range jobs { 21 // fmt.Printf("job: %v\n", job) 22 // } 23 24 var wg sync.WaitGroup 25 wg.Add(1) 26 27 go func() { 28 defer wg.Done() 29 for job := range jobs { 30 fmt.Println(job) 31 } 32 }() 33 34 wg.Wait() 35 }