gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/def/chan.go (about) 1 package def 2 3 func MakeChan[E any](c chan E, size int) chan E { 4 if c == nil { 5 return make(chan E, size) 6 } 7 return c 8 } 9 10 func SetChan[E any](c chan E, def chan E) chan E { 11 if c == nil { 12 return def 13 } 14 return c 15 } 16 17 func SetterChan[E any](c chan E, setter func() chan E) chan E { 18 if c == nil { 19 return setter() 20 } 21 return c 22 } 23 24 func MakeChanP[E any](cp *chan E, size int) { 25 if *cp == nil { 26 *cp = make(chan E, size) 27 } 28 } 29 30 func SetChanP[E any](cp *chan E, def chan E) { 31 if *cp == nil { 32 *cp = def 33 } 34 } 35 36 func SetterChanP[E any](cp *chan E, setter func() chan E) { 37 if *cp == nil { 38 *cp = setter() 39 } 40 }