Beispiel #1
0
 def fn():
     # fork in apparently wrong order!
     broadcast_strand = yield tap.CallFork(broadcaster, (5, ))
     recv_strand = yield tap.CallFork(receiver)
     yield tap.Join(broadcast_strand)
     value = yield tap.Join(recv_strand)
     return value
Beispiel #2
0
 def fn():
     recv_strand = yield tap.CallFork(receiver)
     # even though this is forked, it doesn't end up hanging
     yield tap.CallFork(broadcaster, (5, ))
     value = yield tap.Join(recv_strand)
     # join again should give the same thing, it's already done
     value1 = yield tap.Join(recv_strand)
     assert value1 == value
     return value
Beispiel #3
0
 def fn():
     intercept_strand = yield tap.CallFork(intercepter)
     recv_strand = yield tap.CallFork(receiver)
     # even though this is forked, it doesn't end up hanging
     broadcast_strand = yield tap.CallFork(broadcaster, (5, ))
     value = yield tap.Join(recv_strand)
     assert value == "real"  # got intercepted
     yield tap.Join(intercept_strand)
     yield tap.Cancel(broadcast_strand)
     return value
Beispiel #4
0
 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():
     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)
Beispiel #8
0
 def receiver():
     value = yield tap.Receive('key')
     if value < 10:
         broadcast_strand = yield tap.CallFork(broadcaster, (value + 1, ))
         receive_strand = yield tap.CallFork(receiver)
         yield tap.Join([broadcast_strand, receive_strand])
     raise Exception("too large")
     return value
Beispiel #9
0
 def fn():
     intercept_strand = yield tap.CallFork(intercepter)
     yield tap.Cancel(intercept_strand)
     recv_strand = yield tap.CallFork(receiver)
     # even though this is forked, it doesn't end up hanging
     yield tap.Call(broadcaster, (5, ))
     # this gets intercepted and never gets injected
     yield tap.Join(recv_strand)
Beispiel #10
0
 def fn():
     intercept_strand = yield tap.CallFork(intercepter)
     yield tap.Cancel(intercept_strand)
     recv_strand = yield tap.CallFork(receiver)
     # even though this is forked, it doesn't end up hanging
     yield tap.Call(broadcaster, (5, ))
     value = yield tap.Join(recv_strand)
     assert value == 5  # did *not* get intercepted
     return value
Beispiel #11
0
 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():
        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():
        assert not q.has_work()
        t1 = yield tap.CallFork(pop_and_add)
        t2 = yield tap.CallFork(pop_and_add)
        t3 = yield tap.CallFork(pop_and_add)
        yield tap.Sleep(0)
        assert a == 0
        yield q.Put(3)
        assert a == 3

        yield tap.Cancel(t2)
        yield q.Put(5)
        assert a == 8

        yield q.Put(5)
        assert a == 8

        t4 = yield tap.CallFork(pop_and_add)
        yield tap.Sleep(0)
        assert a == 13

        yield tap.Join([t1, t3, t4])
Beispiel #14
0
 def fn():
     recv_strand = yield tap.CallFork(receiver)
     broadcast_strand = yield tap.CallFork(broadcaster, (5, ))
     yield tap.Join(broadcast_strand)
     value = yield tap.Join(recv_strand)
     return value
Beispiel #15
0
 def fork_fn():
     strand = yield tap.CallFork(random, (5, ))
     x = yield tap.Join(strand)
     return x