示例#1
0
def player(name, table):
    while True:
        ball = yield take(table)
        ball.hits += 1
        print name, ball.hits
        yield sleep(0.1)
        yield put(table, ball)
示例#2
0
def main():
    table = Channel()

    go(player, "ping", table)
    go(player, "pong", table)

    yield put(table, Ball())
    yield sleep(1)
示例#3
0
def main():
    chan = go_chan(lazy_echo, 1)
    print (yield take(chan))

    chan = go_chan(lazy_echo, 2)
    yield sleep(1)
    print (yield take(chan))

    yield stop("Done")
示例#4
0
def produce(chan, value):
    yield sleep(0.1)
    yield put(chan, value)
示例#5
0
 def t():
     yield sleep(seconds)
     chan.close()
 def closing():
     yield sleep(0.005)
     ch.close()
 def taking():
     yield sleep(0.005)
     yield take(ch)
 def putting():
     yield sleep(0.005)
     yield put(ch, 42)
示例#9
0
 def _do():
     i = 0
     while True:
         yield put(c, "%s %d" % (message, i))
         yield sleep(random.random())
         i += 1
示例#10
0
def lazy_echo(x):
    yield sleep(0.1)
    print "I'm done"
    yield stop(x)