def test_parked_put(self): ch = Channel() def putting(): yield sleep(0.005) yield put(ch, 42) go(putting) self.assertEqual((yield take(ch)), 42)
def timeout(seconds): chan = Channel() def t(): yield sleep(seconds) chan.close() go(t) return chan
def taken(value): def checking(): # yield control so that the second put can proceed yield None self.assertEqual(var["count"], 2, "second (buffered) put succeeds") d.callback(CLOSED) go(checking)
def test_parked_taken(self): ch = Channel() def taking(): yield sleep(0.005) yield take(ch) go(taking) self.assertEqual((yield put(ch, 42)), True)
def test_parked_closed(self): ch = Channel() def closing(): yield sleep(0.005) ch.close() go(closing) self.assertEqual((yield put(ch, 42)), False)
def test_parked_closed(self): ch = Channel() def closing(): yield sleep(0.005) ch.close() go(closing) self.assertEqual((yield take(ch)), CLOSED)
def fan_in(input1, input2): c = Channel() def collect(): while True: value, _ = yield alts([input1, input2]) yield put(c, value) go(collect) return c
def main(): table = Channel() go(player, "ping", table) go(player, "pong", table) yield put(table, Ball()) yield sleep(1)
def fan_in(input1, input2): c = Channel() def collect(i): while True: yield put(c, (yield take(i))) go(collect, input1) go(collect, input2) return c
def boring(message): c = Channel() def _do(): i = 0 while True: yield put(c, "%s %d" % (message, i)) yield sleep(random.random()) i += 1 go(_do) return c
def main(): n = 100000 leftmost = Channel() right = leftmost left = leftmost for i in range(n): right = Channel() go(f, left, right) left = right def start(c): yield put(c, 1) go(start, right) print (yield take(leftmost))
def main(): chans = [] for i in range(20): chan = Channel() go(produce, chan, i) chans.append(chan) def timeout(seconds): chan = Channel() def t(): yield sleep(seconds) chan.close() go(t) return chan chans.append(timeout(0.3)) while True: value, chan = yield alts(chans) if value == CLOSED: print "time out" break else: print value
def test_immediate_put(self): ch = Channel() def putting(): yield put(ch, 42) go(putting) self.assertEqual((yield take(ch)), 42)
def test_immediate_taken(self): ch = Channel() def taking(): yield take(ch) go(taking) self.assertEqual((yield put(ch, 42)), True)