I have two functions that receives data from two different connections, and i should close both connections after getting result from one of them.
def first():
gevent.sleep(randint(1, 100)) # i don't know how much time it will work
return 'foo'
def second():
gevent.sleep(randint(1, 100)) # i don't know how much time it will work
return 'bar'
Then i spawn each function:
lst = [gevent.spawn(first), gevent.spawn(second)]
gevent.joinall
blocks current greenlet until both two greenlets from lst
are ready.
gevent.joinall(lst) # wait much time
print lst[0].get(block=False) # -> 'foo'
print lst[1].get(block=False) # -> 'bar'
I want to wait until eiter first or second greenlet become ready:
i_want_such_function(lst) # returns after few seconds
print lst[0].get(block=False) # -> 'foo' because this greenlet is ready
print lst[1].get(block=False) # -> raised Timeout because this greenlet is not ready
How can i do it?