aboutsummaryrefslogtreecommitdiffstats
path: root/slack/task.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2022-10-29 16:57:53 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:52 +0100
commitacaf2e81719ba160aac3bc7c3c78fc4db3d13f65 (patch)
treea23c4c04ac63987312ce2ff9bb6fc1351c887dfe /slack/task.py
parentcdf3cfe4a2ed8a340ac1a8404e7cd7e604fe3857 (diff)
downloadwee-slack-acaf2e81719ba160aac3bc7c3c78fc4db3d13f65.tar.gz
Use class for shared, so we don't have to change usage when combining
Diffstat (limited to 'slack/task.py')
-rw-r--r--slack/task.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/slack/task.py b/slack/task.py
index db914fb..80687a6 100644
--- a/slack/task.py
+++ b/slack/task.py
@@ -5,7 +5,7 @@ from uuid import uuid4
import weechat
-from . import globals as G
+from .shared import shared
from .util import get_callback_name
T = TypeVar("T")
@@ -35,7 +35,7 @@ class Task(Future[T]):
def weechat_task_cb(data: str, *args: Any) -> int:
- task = G.active_tasks.pop(data)
+ task = shared.active_tasks.pop(data)
task_runner(task, args)
return weechat.WEECHAT_RC_OK
@@ -44,26 +44,26 @@ def task_runner(task: Task[Any], response: Any):
while True:
try:
future = task.coroutine.send(response)
- if future.id in G.active_responses:
- response = G.active_responses.pop(future.id)
+ if future.id in shared.active_responses:
+ response = shared.active_responses.pop(future.id)
else:
- if future.id in G.active_tasks:
+ if future.id in shared.active_tasks:
raise Exception(
- f"future.id in active_tasks, {future.id}, {G.active_tasks}"
+ f"future.id in active_tasks, {future.id}, {shared.active_tasks}"
)
- G.active_tasks[future.id] = task
+ shared.active_tasks[future.id] = task
break
except StopIteration as e:
- if task.id in G.active_tasks:
- task = G.active_tasks.pop(task.id)
+ if task.id in shared.active_tasks:
+ task = shared.active_tasks.pop(task.id)
response = e.value
else:
- if task.id in G.active_responses:
+ if task.id in shared.active_responses:
raise Exception( # pylint: disable=raise-missing-from
- f"task.id in active_responses, {task.id}, {G.active_responses}"
+ f"task.id in active_responses, {task.id}, {shared.active_responses}"
)
if not task.final:
- G.active_responses[task.id] = e.value
+ shared.active_responses[task.id] = e.value
break