def socket_coroutine(): print("socket_coroutine start. ") client = socket.socket() client.connect(("", 1234)) buffer = yield get_buffer(client) client.close() print("socket_coroutine stop. ") Return(buffer)
def normal(): a = yield 1 print("Get a: %s" % a) b = yield 2 print("Get b: %s" % b) c = yield 3 print("Get c: %s" % c) Return(c)
def bar(): c = yield 333 print("Got c: ", c) d = yield fun() print("Got d: ", d) e = yield fun() print("Got e", e) Return(c + d + e)
def sum(a, b): print("Sum start. %s + %s" % (a, b)) yield sleep(1) result = yield a + b print("Sum stop. %s + %s" % (a, b)) Return(result)
def aaddcthenmutilb(a, b, c): sum_result = yield sum(a, c) multi_result = yield multi(sum_result, b) Return(multi_result)
def aaddbthenmutilc(a, b, c): sum_result = yield sum(a, b) multi_result = yield multi(sum_result, c) Return(multi_result)
def multi(a, b): print("Multi start. %s x %s" % (a, b)) yield sleep(2) result = yield a * b print("Multi stop. %s x %s" % (a, b)) Return(result)
def fun(): a = yield 111 print("Got a: ", a) b = yield 222 print("Got b: ", b) Return(a + b)