def fn(): assert not q.has_work() t = yield tap.Fork(q.Put(3)) yield tap.Sleep(0.01) assert q.has_work() assert (yield q.Get()) == 3 yield tap.Join(t)
def fn(): strand_1 = yield tap.CallFork(receiver, (1, )) strand_2 = yield tap.CallFork(receiver, (2, )) strand_3 = yield tap.CallFork(receiver, (3, )) results = yield tap.Fork([ tap.First([strand_1, strand_2, strand_3]), tap.First([strand_2, strand_1]), ]) yield tap.Call(broadcaster, (5, )) yield tap.Call(broadcaster, (3, )) yield tap.Call(broadcaster, (1, )) value = yield tap.Join(results) return value
def fn(): strand_1 = yield tap.CallFork(receiver, (1, )) strand_2 = yield tap.CallFork(receiver, (2, )) strand_3 = yield tap.CallFork(receiver, (3, )) results = yield tap.Fork([ tap.First([strand_1, strand_2], name="1v2"), tap.First([strand_2, strand_3], name="2v3"), ]) yield tap.Call(broadcaster, (5, )) yield tap.Call(broadcaster, (1, )) yield tap.Call(broadcaster, (3, )) value = yield tap.Join(results, name="joinfork") yield tap.Join(strand_2, name="joincanceled") return value
def fn(): yield q.Put(3) t1 = yield tap.CallFork(put, (5, )) t2 = yield tap.CallFork(put, (7, )) yield tap.Sleep(0) assert (yield q.Get()) == 3 assert (yield q.Get()) == 5 yield tap.Cancel(t2) # too late assert (yield q.Get()) == 7 yield tap.Join([t1]) t = yield tap.Fork(q.Get()) yield q.Put(3) assert (yield tap.Join(t)) == 3
def fn(): yield q.Put(3) t1 = yield tap.CallFork(put, (5, )) t2 = yield tap.CallFork(put, (7, )) t3 = yield tap.CallFork(put, (9, )) yield tap.Sleep(0) assert (yield q.Get()) == 3 yield tap.Cancel(t2) # not too late to cancel assert (yield q.Get()) == 5 assert (yield q.Get()) == 9 yield tap.Join([t1, t3]) t = yield tap.Fork(q.Get()) yield q.Put(3) assert (yield tap.Join(t)) == 3
def fn(): t = yield tap.Fork(tap.CallThread(thread_fn)) yield tap.Sleep(0.01) assert a == 0 with cv: cv.notify() cv.wait() assert a == 1 with cv: cv.notify() cv.wait() assert a == 2 with cv: cv.notify() assert a == 2 assert (yield tap.Join(t)) == "done"
def fn(): t = yield tap.Fork( tap.Sequence([ tap.CallThread(thread_fn), tap.CallThread(thread_fn), ])) yield tap.Sleep(0.01) assert a == 0 with cv: cv.notify() cv.wait() assert a == 1 # this cancels the second one, but not the first yield tap.Cancel(t) with cv: cv.notify() cv.wait() assert a == 2 with cv: cv.notify() yield tap.Sleep(0.1) assert a == 2
def wake_and_fork(): yield tap.Fork(tap.Broadcast("wake")) yield tap.Fork(tap.Receive("hmm"))