Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
results = []
calls = []
def foo():
def codependant(*args, **kw):
calls.append((args, kw))
return 42
return txaio.as_future(codependant)
def method(*args, **kw):
calls.append((args, kw))
return "OHAI"
f0 = txaio.as_future(method, 1, 2, 3, key='word')
f1 = txaio.as_future(foo)
f2 = txaio.gather([f0, f1])
def done(arg):
results.append(arg)
def error(fail):
errors.append(fail)
# fail.printTraceback()
txaio.add_callbacks(f2, done, error)
for f in [f0, f1, f2]:
_await(f)
assert len(results) == 1
assert len(errors) == 0
assert results[0] == ['OHAI', 42] or results[0] == [42, 'OHAI']
assert len(calls) == 2
d = txaio.as_future(comp.start, reactor)
txaio.add_callbacks(
d,
partial(component_success, comp),
partial(component_failure, comp),
)
return d
# note that these are started in parallel -- maybe we want to add
# a "connected" signal to components so we could start them in the
# order they're given to run() as "a" solution to dependencies.
dl = []
for comp in components:
d = component_start(comp)
dl.append(d)
done_d = txaio.gather(dl, consume_exceptions=False)
def all_done(arg):
log.debug("All components ended; stopping reactor")
if isinstance(arg, Failure):
log.error("Something went wrong: {log_failure}", failure=arg)
try:
reactor.stop()
except ReactorNotRunning:
pass
txaio.add_callbacks(done_d, all_done, all_done)
return done_d
for k in inspect.getmembers(handler.__class__, is_method_or_function):
proc = k[1]
if "_wampuris" in proc.__dict__:
for pat in proc.__dict__["_wampuris"]:
if pat.is_handler():
_uri = pat.uri()
subopts = pat.options or options
if subopts is None:
if pat.uri_type == uri.Pattern.URI_TYPE_WILDCARD:
subopts = types.SubscribeOptions(match=u"wildcard")
else:
subopts = types.SubscribeOptions(match=u"exact")
on_replies.append(_subscribe(handler, proc, _uri, subopts))
# XXX needs coverage
return txaio.gather(on_replies, consume_exceptions=True)
receiver)
if receivers:
# still more to do ..
return txaio.call_later(0, _notify_some, receivers)
else:
# all done! resolve all_d, which represents all receivers
# to a single subscription matching the event
txaio.resolve(all_d, None)
_notify_some([
recv for recv in receivers
if (me_also or recv != session) and recv != self._event_store
])
return txaio.gather(all_dl)
else:
# register all methods on an object decorated with "wamp.register"
on_replies = []
for k in inspect.getmembers(endpoint.__class__, is_method_or_function):
proc = k[1]
if "_wampuris" in proc.__dict__:
for pat in proc.__dict__["_wampuris"]:
if pat.is_endpoint():
_uri = pat.uri()
regopts = pat.options or options
on_replies.append(_register(endpoint, proc, _uri, regopts))
# XXX needs coverage
return txaio.gather(on_replies, consume_exceptions=True)
:return: a Deferred/Future gathering all async results from
all handlers and/or parent handlers.
"""
# print("firing '{}' from '{}'".format(event, hash(self)))
if self._listeners is None:
return txaio.create_future(result=[])
self._check_event(event)
res = []
for handler in self._listeners.get(event, []):
future = txaio.as_future(handler, *args, **kwargs)
res.append(future)
if self._parent is not None:
res.append(self._parent.fire(event, *args, **kwargs))
return txaio.gather(res, consume_exceptions=False)
d = txaio.as_future(comp.start, reactor)
txaio.add_callbacks(
d,
partial(component_success, comp),
partial(component_failure, comp),
)
return d
# note that these are started in parallel -- maybe we want to add
# a "connected" signal to components so we could start them in the
# order they're given to run() as "a" solution to dependencies.
dl = []
for comp in components:
d = component_start(comp)
dl.append(d)
done_d = txaio.gather(dl, consume_exceptions=False)
def all_done(arg):
log.debug("All components ended; stopping reactor")
done_callback(reactor, arg)
txaio.add_callbacks(done_d, all_done, all_done)
return done_d