Exemplo n.º 1
0
 def transition(self, state, data=None) -> Promise:
     async def do_side_effects():
         await asyncio.wait(map(
             lambda f: asyncio.ensure_future(f()),
             self._transition_table[(self.state.name, state.name)]
         ))
         self.state = state
     return Promise.promisify(asyncio.ensure_future(do_side_effects()))
Exemplo n.º 2
0
def promise_factorial(n):
    if n < 2:
        return 1
    sleep(.02)
    a = executor.submit(promise_factorial, n - 1)

    def promise_then(r):
        return mul(r, n)

    return Promise.promisify(a).then(promise_then)
Exemplo n.º 3
0
def promise_factorial(n):
    if n < 2:
        return 1
    sleep(.02)
    a = executor.submit(promise_factorial, n - 1)
    return Promise.promisify(a).then(lambda r: mul(r, n))