Suppose:
- There is some object (e.g., an array
a
) and a condition dependent on the object (e.g., such asa.empty?
). - Some threads other than the current thread can manipulate the object (
a
), so the truthness of the evaluated value of the condition changes over the time.
How can I let the current thread sleep at some point in the code and continue (wake up) by push notification when the condition is satisfied?
I do not want to do polling like this:
...
sleep 1 until a.empty?
...
Perhaps using Fiber
will be a clue.