新增on_keywords

This commit is contained in:
2024-08-22 09:35:02 +08:00
parent a3a31a2c94
commit 4bf8512a7d
12 changed files with 137 additions and 22 deletions

View File

@ -38,7 +38,7 @@ class Channel(Generic[T]):
有两种接收工作方式,但是只能选择一种,主动接收和被动接收,主动接收使用 `receive` 方法,被动接收使用 `on_receive` 装饰器
"""
def __init__(self, _id: str, type_check: Optional[bool] = None):
def __init__(self, _id: str = "", type_check: Optional[bool] = None):
"""
初始化通道
Args:

View File

@ -8,7 +8,7 @@ from typing import Any, Coroutine, Optional, TypeAlias, Callable
from liteyuki.comm import channel
from liteyuki.comm.channel import Channel, ON_RECEIVE_FUNC, ASYNC_ON_RECEIVE_FUNC
from liteyuki.utils import IS_MAIN_PROCESS, is_coroutine_callable, run_coroutine
from liteyuki.utils import IS_MAIN_PROCESS, is_coroutine_callable, run_coroutine, run_coroutine_in_thread
if IS_MAIN_PROCESS:
_locks = {}
@ -220,10 +220,10 @@ class KeyValueStore:
"""
if IS_MAIN_PROCESS:
if channel_ in _on_main_subscriber_receive_funcs and _on_main_subscriber_receive_funcs[channel_]:
run_coroutine(*[func(data) for func in _on_main_subscriber_receive_funcs[channel_]])
run_coroutine_in_thread(*[func(data) for func in _on_main_subscriber_receive_funcs[channel_]])
else:
if channel_ in _on_sub_subscriber_receive_funcs and _on_sub_subscriber_receive_funcs[channel_]:
run_coroutine(*[func(data) for func in _on_sub_subscriber_receive_funcs[channel_]])
run_coroutine_in_thread(*[func(data) for func in _on_sub_subscriber_receive_funcs[channel_]])
def _start_receive_loop(self):
"""