github.com/tursom/GoCollections@v0.3.10/lang/Channel_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 lang 8 9 import ( 10 "fmt" 11 "testing" 12 13 "github.com/tursom/GoCollections/util/time" 14 ) 15 16 func TestChannel_Send(t *testing.T) { 17 ch := NewChannel[int](0) 18 19 fmt.Println(ch.TrySend(0)) 20 21 go func() { 22 for i := range ch { 23 fmt.Println(i) 24 } 25 }() 26 27 ch.Send(1) 28 ch.SCh() <- 2 29 time.Sleep(time.Second / 10) 30 fmt.Println(ch.TrySend(3)) 31 32 ch.Close() 33 }