mirror of https://github.com/Shizmob/pydle.git
Properly show exceptions in coroutines.
This commit is contained in:
parent
bdec13274d
commit
dfc53ef4bb
|
@ -37,20 +37,14 @@ def coroutine(func):
|
|||
result.add_done_callback(handle_future)
|
||||
except StopIteration as e:
|
||||
return_future.set_result(getattr(e, 'value', None))
|
||||
except Exception as e:
|
||||
return_future.set_exception(e)
|
||||
|
||||
try:
|
||||
# Handle initial value.
|
||||
gen = func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
return_future.set_exception(e)
|
||||
# Handle initial value.
|
||||
gen = func(*args, **kwargs)
|
||||
|
||||
# If this isn't a generator, then wrap the result with a future.
|
||||
if not isinstance(gen, types.GeneratorType):
|
||||
return_future.set_result(gen)
|
||||
return return_future
|
||||
else:
|
||||
# If this isn't a generator, then wrap the result with a future.
|
||||
if not isinstance(gen, types.GeneratorType):
|
||||
return_future.set_result(gen)
|
||||
return return_future
|
||||
|
||||
try:
|
||||
result = next(gen)
|
||||
|
@ -59,8 +53,6 @@ def coroutine(func):
|
|||
result.add_done_callback(handle_future)
|
||||
except StopIteration as e:
|
||||
return_future.set_result(getattr(e, 'value', None))
|
||||
except Exception as e:
|
||||
return_future.set_exception(e)
|
||||
|
||||
return return_future
|
||||
return wrapper
|
||||
|
|
Loading…
Reference in New Issue