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 | |
parent | adf20323ce99e8829a2ab53f8d487f5704d28320 (diff) | |
download | wee-slack-81e98c8b7049fd08886ba7099bba02130b6026a2.tar.gz |
Remove active_responses
Diffstat (limited to 'slack')
-rw-r--r-- | slack/commands.py | 2 | ||||
-rw-r--r-- | slack/init.py | 2 | ||||
-rw-r--r-- | slack/shared.py | 3 | ||||
-rw-r--r-- | slack/task.py | 23 |
4 files changed, 9 insertions, 21 deletions
diff --git a/slack/commands.py b/slack/commands.py index c9c62ee..735ba35 100644 --- a/slack/commands.py +++ b/slack/commands.py @@ -115,7 +115,7 @@ def command_slack_connect( for workspace in shared.workspaces.values(): await workspace.connect() - create_task(connect(), final=True) + create_task(connect()) @weechat_command() diff --git a/slack/init.py b/slack/init.py index 68da138..b126a24 100644 --- a/slack/init.py +++ b/slack/init.py @@ -88,4 +88,4 @@ def main(): "", ) - create_task(init(), final=True) + create_task(init()) diff --git a/slack/shared.py b/slack/shared.py index f972c2b..eab2c92 100644 --- a/slack/shared.py +++ b/slack/shared.py @@ -1,7 +1,7 @@ from __future__ import annotations from collections import defaultdict -from typing import TYPE_CHECKING, Any, Dict, List, Tuple +from typing import TYPE_CHECKING, Any, Dict, List if TYPE_CHECKING: from slack.api import SlackWorkspace @@ -18,7 +18,6 @@ class Shared: self.weechat_callbacks: Dict[str, Any] self.active_tasks: Dict[str, List[Task[Any]]] = defaultdict(list) self.active_futures: Dict[str, Future[Any]] = {} - self.active_responses: Dict[str, Tuple[Any, ...]] = {} self.workspaces: Dict[str, SlackWorkspace] = {} self.config: SlackConfig 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 |