Checking if a channel has a ready-to-read value, using Go -
How do I check if I have a value to read a channel?
I do not want to block a channel while reading. I want to see if it has the value or not. If it is one, then I will read it. If this is not one (yet), then I will do something else and check back later.
Thank you!
warning : it is no longer correct, see the answers given below.
From Docs:
If a received expression is used in the initialization of assignment or form
x, Ok = & lt; -ch x, ok: = & lt; -ch var x, ok = & lt; -ch
The action received is non-blocking if the operation can proceed, the boolean variable will be set to OK and values stored in the x; Otherwise the right is set to False and X is set to zero value for its type
Comments
Post a Comment