syrusakbary / promise

Ultra-performant Promise implementation in Python
MIT License
362 stars 76 forks source link

then() doesn't take on promise returned by called handler #32

Closed Nakroma closed 7 years ago

Nakroma commented 7 years ago

In the docs its stated that The call to .then also returns a promise. If the handler that is called returns a promise, the promise returned by .then takes on the state of that returned promise.
So .then(my_func()) should take on the promise returned by my_func()

Take a look at this example:

def testfunc():
    return Promise(lambda resolve, reject: resolve("second"))

Promise(lambda resolve, reject: resolve("first")).then(testfunc()).then(lambda res: print(res))

The first .then should take on the state of the promise returned by testfunc(), so in theory the second .then should print out "second". But this is not what happens, instead it prints out "first" from the first promise.

Nakroma commented 7 years ago

Nevermind. Apparently resolve() absolutely needs an argument and the function absolutely needs a lambda.