diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-01-12 23:01:18 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | 81e98c8b7049fd08886ba7099bba02130b6026a2 (patch) | |
tree | f8211fa973ea09f0c3ea918ec97209b543c13241 /slack/task.py | |
parent | adf20323ce99e8829a2ab53f8d487f5704d28320 (diff) | |
download | wee-slack-81e98c8b7049fd08886ba7099bba02130b6026a2.tar.gz |
Remove active_responses
Diffstat (limited to 'slack/task.py')
-rw-r--r-- | slack/task.py | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/slack/task.py b/slack/task.py index 0612985..8f4e58d 100644 --- a/slack/task.py +++ b/slack/task.py @@ -43,10 +43,9 @@ class FutureTimer(Future[Tuple[int]]): class Task(Future[T]): - def __init__(self, coroutine: Coroutine[Future[Any], Any, T], final: bool): + def __init__(self, coroutine: Coroutine[Future[Any], Any, T]): super().__init__() self.coroutine = coroutine - self.final = final def weechat_task_cb(data: str, *args: Any) -> int: @@ -62,9 +61,7 @@ def task_runner(task: Task[Any], response: Any): while True: try: future = task.coroutine.send(response) - if future.id in shared.active_responses: - response = shared.active_responses.pop(future.id) - elif future.result is not None: + if future.result is not None: response = future.result else: shared.active_tasks[future.id].append(task) @@ -76,21 +73,13 @@ def task_runner(task: Task[Any], response: Any): tasks = shared.active_tasks.pop(task.id) for active_task in tasks: task_runner(active_task, e.value) - break - - if task.id in shared.active_responses: - raise Exception( # pylint: disable=raise-missing-from - f"task.id in active_responses, {task.id}, {shared.active_responses}" - ) - if not task.final: - shared.active_responses[task.id] = e.value + if task.id in shared.active_futures: + del shared.active_futures[task.id] break -def create_task( - coroutine: Coroutine[Future[Any], Any, T], final: bool = False -) -> Task[T]: - task = Task(coroutine, final) +def create_task(coroutine: Coroutine[Future[Any], Any, T]) -> Task[T]: + task = Task(coroutine) task_runner(task, None) return task |