Hi,

THanks!!

BR
Abraham

On Friday, November 27, 2020 at 11:12:53 AM UTC+2 b.ca...@pobox.com wrote:

> On Friday, 27 November 2020 at 06:14:48 UTC Afriyie Abraham Kwabena wrote:
>
>> What I would like to ask is, using mutex OK and if not the best way of 
>> solving it, how can i use
>> channels in this case.
>>
>
> There's nothing wrong with mutex, but you can use channels for a more 
> native-Go experience.
> This video is well worth watching: 
> https://www.youtube.com/watch?v=5zXAHh5tJqQ
>
> In short, you can get mutex or semaphore-like behaviour by having a 
> channel with fixed depth, and putting/pulling values from it.
> Playground <https://play.golang.org/p/Vg-c8v7N0-6>
>
> mutex := make(chan struct{}, 1)
> ...
>
> mutex <- struct{}{}
> ... do stuff
> <-mutex
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e59c6a22-030c-479a-ba8a-b61948307b62n%40googlegroups.com.

Reply via email to