github.com/tursom/GoCollections@v0.3.10/concurrent/collections/Sequence_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 collections 8 9 import ( 10 "fmt" 11 "math/rand" 12 "testing" 13 14 "github.com/tursom/GoCollections/util/time" 15 ) 16 17 func TestSequence_Alloc(t *testing.T) { 18 var sequence Sequence[int] 19 go func() { 20 for i := range sequence.RawChannel() { 21 fmt.Println(i) 22 } 23 }() 24 25 for i := 0; i < 10000; i++ { 26 id := i 27 sender := sequence.Alloc() 28 go func() { 29 time.Sleep(time.Duration(rand.Float32() * float32(time.Second) * 5 * (float32(id) / 10000))) 30 sender.Send(id) 31 }() 32 } 33 time.Sleep(time.Second * 10) 34 sequence.Close() 35 }