Managers use callback functions instead of signals

This commit is contained in:
GeoffreyCoulaud
2023-05-29 00:23:25 +02:00
parent b99c058cd7
commit 8ddb110cbb
3 changed files with 19 additions and 34 deletions

View File

@@ -1,3 +1,5 @@
from typing import Callable
from gi.repository import Gio
from src.game import Game
@@ -24,18 +26,17 @@ class AsyncManager(Manager):
Already scheduled Tasks will no longer be cancellable."""
self.cancellable = Gio.Cancellable()
def run(self, game: Game) -> None:
data = (game,)
task = Task.new(self, self.cancellable, self._task_callback, data)
task.set_task_data(data)
def run(self, game: Game, callback: Callable) -> None:
task = Task.new(self, self.cancellable, self._task_callback, (callback,))
task.set_task_data((game,))
task.run_in_thread(self._task_thread_func)
def _task_thread_func(self, _task, _source_object, data, cancellable):
"""Task thread entry point"""
game, *_rest = data
self.emit("started")
self.final_run(game)
def _task_callback(self, _source_object, _result, _data):
def _task_callback(self, _source_object, _result, data):
"""Method run after the async task is done"""
self.emit("done")
_game, callback, *_rest = data
callback(self)