1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
from threading import Event
if False:
from ..promise import Promise
from typing import Callable, Any, Optional # flake8: noqa
class ImmediateScheduler(object):
def call(self, fn):
# type: (Callable) -> None
try:
fn()
except:
pass
def wait(self, promise, timeout=None):
# type: (Promise, Optional[float]) -> None
e = Event()
def on_resolve_or_reject(_):
# type: (Any) -> None
e.set()
promise._then(on_resolve_or_reject, on_resolve_or_reject)
waited = e.wait(timeout)
if not waited:
raise Exception("Timeout")
|