One more thing, if you want the wait condition to be grouped in a select{}
use the .Channel() method to get the channel. The Wait helper method does
this with a timeout, as an example. After the signal the channel is dead so
you have to use Channel() again to get the new one. If you're using it
I needed something similar to ManualResetEvent in C# here is what I'm using
atm.
https://play.golang.org/p/UUyyK8ifku
This is attempting to be an edit, this example works better.
Also there is a helper method on the struct if don't want to wait forever
Wait has a timeout option. Although there
I've needed something similar. Its like a ManualResetEvent in C#, here is
some test code and the struct I use:
https://play.golang.org/p/mvSMwMZX51
Note running that on playground will timeout due to everything being
asleep, but this gets the idea across.
On Sunday, September 4, 2016 at 4:29:1
On 09/05/2016 12:14 AM, Jason E. Aten wrote:
Or perhaps it is because sync.WaitGroup and sync.Cond (condition
variables) exist. They
aren't select{}-friendly, but they usually do the job.
Yes they aren't select{}-friendly. sync.Cond for example looks like
right choice but just blocks.
--
I've often had similar thoughts.
Getting started with Go, a barrier synchronizer
that played nice with channels seems like a natural
idea.
But there's not one as far as I know.
Perhaps that's because it's not difficult to build one. Or
because it puts the cleanup onus on the garbage collector.
I've often had similar thoughts.
Getting started with Go, a barrier synchronizer
that played nice with channels seems like natural
a natural.
But there's not one as far as I know.
Perhaps that's because it's not difficult to build one. Or
because it puts the cleanup onus on the garbage collect
It's neither meaningful nor safe. :)
Since you're writing a variable that can be read in another goroutine
without establishing any sort of ordering, this code is unsafe. The issue
happens with any code like:
func main() {
var ch chan int
go func() { <-ch }()
ch = make(chan int)
}
The sp