def update(self, x, who=None): y = x + self.args result = self.func(*y, **self.kwargs) if gen.isawaitable(result): return result else: return []
def add_singleton( self, service: Union[Type[IDispose], Type[Awaitable]]) -> IStartup: key = service.__name__ service_instance = service(self.launch) if isawaitable(service_instance): IOLoop.instance().add_future( convert_yielded(service_instance), lambda v: gen_log.info( "%s asynchronous registration singleton completed", key)) self.singleton_services[key] = service_instance return self
def run(self): """ run coroutine or normal function all in coroutine style """ func_like = self.wrapped_callable(self.callable, *self.args, **self.kw_args) coro_like = func_like() if isawaitable(coro_like): yield coro_like
async def destroy(self): """ 销毁注册的单例服务 :return: """ for key in self.singleton: d = self.singleton[key].destroy() if isawaitable(d): await d
async def async_on_finish(self) -> NoReturn: """ 自动回收scoped注册服务对象调用destroy()方法, 可支持异步销毁和同步销毁方式 :return: """ scoped = self.application.scoped for key in scoped: s = getattr(self, key, None) if s: d = s.destroy() if isawaitable(d): await d
def update(self, x, who=None, metadata=None): result = self.func(x, *self.args, **self.kwargs) if gen.isawaitable(result): return result else: return []
def update(self, x, who=None): result = self.func(x) if gen.isawaitable(result): return result else: return []