我关于 StackOverflow 的第一个问题:D
我正在运行 1.16。我创建了这个函数:
func (_m *MyPool) InChannel(outs ...chan interface{}) error {
for _, out := range outs {
out = _m.inChan
}
return nil
}
Run Code Online (Sandbox Code Playgroud)
MyPool 是一种工作池类型,其中包含以下成员:
type MyPool struct {
inChan chan interface{}
}
Run Code Online (Sandbox Code Playgroud)
我的主要问题是 Go 正在标记out循环变量在InChannel. 这是为什么?我确实在用...
抱歉,我是 StackOverflow 的菜鸟,所以我正在编辑以澄清一点。我确实想分配,而不是发送。这是因为发送方将有一个outChan chan interface{}作为成员变量,并将通过以下方式发送值:
func (s *Sender) Out(out interface{}) {
select {
case <-s.Ctx.Done():
return
case s.outChan <- out:
return
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:所以我最终通过执行以下操作来解决它:
func (m *MyPool) InChannel(outs ...*chan interface{}) error { …Run Code Online (Sandbox Code Playgroud)