def f(): lst = [1] coro_f = Coroutine.getcurrent() coro_g = self.Coroutine() coro_h = self.Coroutine() coros = [coro_f, coro_g, coro_h] thunk_g = T(g, lst, coros) output('binding g after f set 1') coro_g.bind(thunk_g) thunk_h = T(h, lst, coros) output('binding h after f set 1') coro_h.bind(thunk_h) output('switching to g') coro_g.switch() lst.append(4) output('f appended 4') coro_g.switch() lst.append(6) output('f appended 6') coro_h.switch() lst.append(8) output('f appended 8') n = 0 for i in lst: n = n * 10 + i return n
def f(): lst = [1] coro_f = Coroutine.getcurrent() coro_g = self.Coroutine() coro_h = self.Coroutine() coros = [coro_f, coro_g, coro_h] thunk_g = T(g, lst, coros) output('binding g after f set 1') coro_g.bind(thunk_g) thunk_h = T(h, lst, coros) output('binding h after f set 1') coro_h.bind(thunk_h) output('switching to g') coro_g.switch() lst.append(4) output('f appended 4') coro_g.switch() lst.append(6) output('f appended 6') coro_h.switch() lst.append(8) output('f appended 8') n = 0 for i in lst: n = n*10 + i return n
def f(): coro_f = Coroutine.getcurrent() coro_f.__name__ = 'coro_f' coro_f1 = self.Coroutine() coro_f1.__name__ = 'coro_f1' thunk_f1 = T1(f1, coro_f1) output('binding f1 after f set 1') coro_f1.bind(thunk_f1) coro_f1.switch() output('return to main :-(') return thunk_f1.res
def f(): coro_f = Coroutine.getcurrent() coro_f.__name__ = 'coro_f' coro_f1 = self.Coroutine() coro_f1.__name__ = 'coro_f1' thunk_f1 = T1(f1, coro_f1) output('binding f1 after f set 1') coro_f1.bind(thunk_f1) coro_f1.switch() output('return to main :-(') return thunk_f1.res