channel

Refactor code to use a single channel in an idiomatic way

隐身守侯 提交于 2020-12-13 03:13:10
问题 I have the following code: package main import ( "fmt" "time" ) type Response struct { Data string Status int } func main() { var rc [10]chan Response for i := 0; i < 10; i++ { rc[i] = make(chan Response) } var responses []Response for i := 0; i < 10; i++ { go func(c chan<- Response, n int) { c <- GetData(n) close(c) }(rc[i], i) } for _, resp := range rc { responses = append(responses, <-resp) } for _, item := range responses { fmt.Printf("%+v\n", item) } } func GetData(n int) Response { time

Django Websockets Data going to the wrong Socket

↘锁芯ラ 提交于 2020-12-10 09:14:35
问题 Using Django Websockets + Channels, I create a (One) group and the message back and forth works just fine. Lets call this Group A The problem starts when I open a SECOND group and a SECOND (Lets call this group B) WebSocket connection in a different browser. The messages that I am trying to send to group A (first WebSocket connection), are going to group B (second WebSocket connection). All the messages that belong to group A go to the second WebSocket and the group B messages also go to the

Django Websockets Data going to the wrong Socket

和自甴很熟 提交于 2020-12-10 09:13:32
问题 Using Django Websockets + Channels, I create a (One) group and the message back and forth works just fine. Lets call this Group A The problem starts when I open a SECOND group and a SECOND (Lets call this group B) WebSocket connection in a different browser. The messages that I am trying to send to group A (first WebSocket connection), are going to group B (second WebSocket connection). All the messages that belong to group A go to the second WebSocket and the group B messages also go to the

Django Websockets Data going to the wrong Socket

别说谁变了你拦得住时间么 提交于 2020-12-10 09:08:27
问题 Using Django Websockets + Channels, I create a (One) group and the message back and forth works just fine. Lets call this Group A The problem starts when I open a SECOND group and a SECOND (Lets call this group B) WebSocket connection in a different browser. The messages that I am trying to send to group A (first WebSocket connection), are going to group B (second WebSocket connection). All the messages that belong to group A go to the second WebSocket and the group B messages also go to the