예제 #1
0
 async def getKwargs(kwargs):
     kwargsTasks = [
         arg.map(lambda x: (ith, x))
         if isinstance(arg, Awaitable) else Promise.insert((ith, arg))
         for ith, arg in kwargs.items()
     ]
     return dict(await asyncio.gather(*kwargsTasks))
예제 #2
0
async def main():

    x = Promise.insert(1).map(fakeComputation)

    y = Promise.insert(2).map(fakeComputation)

    z = Promise.insert(3).map(fakeComputation)

    # z = add(x, y)

    # promiseSum = add(x, y, z)
    promiseSum = my_func(x, y=1, z=z)

    final_result = promiseSum.map(fakeComputation)

    print(
        "Here we have instantiated the computation, but we have not done anything"
    )

    value = await final_result

    print(value)
예제 #3
0
def dbl(value):
    return Promise(lambda resolve, reject: resolve(2 * value))
예제 #4
0
def dec(value):
    return Promise(lambda resolve, reject: resolve(value - 1))
예제 #5
0
def inc(value):
    return Promise(lambda resolve, reject: resolve(value + 1))
예제 #6
0
 def test_catch(self):
     p = _run(
         Promise(lambda resolve, reject: reject(IndexError())).catch(
             lambda error: 0))
     self.assertEqual(p, 0)
예제 #7
0
 def test_insert(self):
     self.assertEqual(_run(Promise.insert(0)), 0)
예제 #8
0
def pipeline(steps, value) -> _Promise[Either]:
    promise = Promise.insert(Right(value))
    return reduce(lambda either, step: either.then(lambda x: x.bind(step)), steps, promise)
예제 #9
0
 async def getArgs(args):
     return await asyncio.gather(*[
         arg if isinstance(arg, Awaitable) else Promise.insert(arg)
         for arg in args
     ])
예제 #10
0
def pipeline(steps, value) -> _Promise[Either]:
    return reduce(lambda promise, step: promise.then(step), steps, Promise.insert(value))\
        .map(lambda x: Right(x)).catch(errorHandling)