Deferred promise does not handle reject
Opened this issue · 0 comments
DmitryPorotov commented
This is my code:
from promise import Promise
from threading import Timer
from time import sleep
class MyClass:
def __init__(self):
self.p = None
def get_promise(self):
self.p = Promise()
def reject():
self.p.reject(Exception("qwe"))
def resolve():
self.p.fulfill("asd")
Timer(3, reject).start()
return self.p
i = MyClass()
def on_resolve(x):
print(str(x))
def on_reject(x):
print(str(x))
p = i.get_promise()
p.then(on_resolve, on_reject)
while 1:
sleep(1)
on_reject
is never called in the master branch version (2.1.0). But it works fine in 1.0.1.
I've stepped through execution and I think I might have found the problem. I saw that the code goes to this function:
def _reject(self, reason, traceback=None):
self._state = STATE_REJECTED
self._fulfillment_handler0 = reason
self._traceback = traceback
if self._is_final:
assert self._length == 0
return async_instance.fatal_error(reason)
if self._length > 0:
async_instance.settle_promises(self)
else:
self._ensure_possible_rejection_handled() # the execution goes here
if self._is_async_guaranteed:
self._settle_promises()
else:
async_instance.settle_promises(self)
But _ensure_possible_rejection_handled
does nothing:
def _ensure_possible_rejection_handled(self):
# self._rejection_is_unhandled = True
# async_instance.invoke_later(self._notify_unhandled_rejection, self)
pass
Is it a bug or am I doing something wrong?