Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
resolve.__jailed_pairs__ = reject
reject.__jailed_pairs__ = resolve
self.emit(
{
"type": "callback",
"id": id_,
"num": arg_num,
# 'pid' : self.id,
"args": self._wrap(arguments),
"promise": self._wrap([resolve, reject]),
}
)
if PYTHON3:
return FuturePromise(pfunc, self.client.loop)
return Promise(pfunc)
def pfunc(resolve, reject):
resolve.__jailed_pairs__ = reject
reject.__jailed_pairs__ = resolve
call_func = {
"type": "method",
"name": name,
"pid": plugin_id,
"args": self._wrap(arguments),
"promise": self._wrap([resolve, reject]),
}
self.emit(call_func)
if PYTHON3:
return FuturePromise(pfunc, self.client.loop)
return Promise(pfunc)
def __init__(self, pfunc, loop):
"""Set up promise."""
self.loop = loop
Promise.__init__(self, pfunc)
asyncio.Future.__init__(self)
import asyncio
from imjoy.workers.worker_utils import Promise
def make_coro(func):
"""Wrap a normal function with a coroutine."""
async def wrapper(*args, **kwargs):
"""Run the normal function."""
return func(*args, **kwargs)
return wrapper
class FuturePromise(Promise, asyncio.Future):
"""Represent a promise as a future."""
def __init__(self, pfunc, loop):
"""Set up promise."""
self.loop = loop
Promise.__init__(self, pfunc)
asyncio.Future.__init__(self)
def resolve(self, result):
"""Resolve promise."""
if self._resolve_handler or self._finally_handler:
super().resolve(result)
else:
self.loop.call_soon(self.set_result, result)
def reject(self, error):