Hello,
I wish to get a operate which may recieve any sort of chan as arguments,
(eg. chan int, chan chan int, chan myType …),
ch := make(chan int, 1)
ch2:= make(chan chan int, 2)
fn(ch)
fn(ch2)
is there any approach?
Hello @moskong ,
A operate with a sort parameter is what you want:
func [T any](c chan T)() {}
This operate makes use of a sort parameter T that may be substituted by any sort. The operate parameter c
is a chan of sort T
, which matches any channel sort.
2 Likes
Hello, @christophberger. Thanks to your assist, it helps me so much.
And as we speak, I get a superior drawback, is there any approach we are able to make it help any route of chan? l do this however it appears not work.
func fn[T any, C chan T | <-chan T | chan<- T](o C)
I feel a get an answer about the issue above
func fn[T any | chan T | <-chan T | chan<- T](o T)