This commit is contained in:
yumoqing 2024-07-23 18:02:51 +08:00
parent 3877126d03
commit 488a578a16

View File

@ -3,6 +3,7 @@ from inspect import isfunction, iscoroutinefunction
from functools import partial from functools import partial
from appPublic.dictObject import DictObject from appPublic.dictObject import DictObject
from appPublic.Singleton import SingletonDecorator from appPublic.Singleton import SingletonDecorator
from appPublic.log import info, error
@SingletonDecorator @SingletonDecorator
class RegisterFunction: class RegisterFunction:
@ -18,11 +19,13 @@ class RegisterFunction:
def get(self,name): def get(self,name):
return self.registKW.get(name,None) return self.registKW.get(name,None)
async def exe(name, *args, **kw): async def exe(self, name, *args, **kw):
f = self.get(name) f = self.get(name)
if f is None: if f is None:
error(f'{name=} function not registed')
return None return None
if iscoroutinefunction(f): if iscoroutinefunction(f):
info(f'{name=} is coroutine function');
return await f(*args, **kw) return await f(*args, **kw)
return f(*args, **kw) return f(*args, **kw)
@ -40,7 +43,10 @@ class RegisterCoroutine:
else: else:
self.kw[name].append(func) self.kw[name].append(func)
async def exe(self, name, *args, **kw): async def exe(self, name, *args, **kw):
fs = self.kw.get(name).copy() fs = self.kw.get(name)
if fs is None:
return
fs = fs.copy()
fs.reverse() fs.reverse()
if fs: if fs:
for f in fs: for f in fs: