I am trying to figure out whether I can reopen a channel after closing it.
Test case:
- I have a channel with some things in it
- I want to range over them therefore I need to close the channel beforehand
- I want to put more stuff in the channel and iterate through it once more
go func() {
queue <- "1"
queue <- "2"
close(queue)
}()
for i := range queue {
go func(i string) {
fmt.Println("From queue: ", i)
}(i)
}
go func() {
open(queue)
queue <- "3"
queue <- "4"
close(queue)
}()
for i := range queue {
go func(i string) {
fmt.Println("From queue: ", i)
}(i)
}
- Of course
opendoes not exist. How can I implement something like what I need in Go? - I don't want to use the Sleep function