代码拉取完成,页面将自动刷新
package concurrent
import "reflect"
// FanInRec 扇入模式
func FanInRec(channels ...<-chan interface{}) <-chan interface{} {
out := make(chan interface{}, 1)
go func() {
defer close(out)
var cases []reflect.SelectCase
for _, channel := range channels {
cases = append(cases, reflect.SelectCase{
Dir: reflect.SelectRecv,
Chan: reflect.ValueOf(channel),
})
}
for len(cases) > 0 {
i, v, ok := reflect.Select(cases)
if !ok {
// 监控的channel已经关闭
cases = append(cases[:i], cases[i+1:]...)
continue
}
out <- v.Interface()
}
}()
return out
}
// MergeChannel 合并两个channel
func MergeChannel(a, b <-chan interface{}) <-chan interface{} {
c := make(chan interface{})
go func() {
defer close(c)
for a != nil || b != nil {
select {
case v, ok := <-a:
if !ok {
a = nil
continue
}
c <- v
case v, ok := <-b:
if !ok {
b = nil
continue
}
c <- v
}
}
}()
return c
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。