Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

threads.thread_controlモジュール: pause/resumeのイベント処理の実装 #38

Open
3 tasks
Geson-anko opened this issue Feb 7, 2025 · 0 comments
Open
3 tasks
Assignees
Labels
enhancement New feature or request

Comments

@Geson-anko
Copy link
Member

Geson-anko commented Feb 7, 2025

タスク内容

#35 に、Pause/Resumeが実行された際のイベント呼び出し処理を実装します。

実装

  • ControllerCommandHandlerのstop_if_pauseに実装します。
  • Pause/Resumeイベントのインターフェイスを注入できるMixinクラスも定義します。

スケッチ

イベント処理

from typing import Callable

type OnPausedCallbackType = Callable[[], None]
type OnResumedCallbackType = Callable[[], None]

class ControllerCommandHandler:
    def __init__(
        self, 
        controller: ReadOnlyController,
        on_paused_callback: OnPausedCallbackType = lambda : None,
        on_resumed_callback: OnResumedCallbackType = lambda: None,
    ):
        self._controller = controller
        self.on_paused = on_paused_callback
        self.on_resumed = on_resumed_callback

    def stop_if_pause(self, check_resume_interval: float = 1.0) -> None:

        paused = False
        if self._controller.is_pause():
            self.on_paused()
            paused = True

        while not self._controller.wait_for_resume(check_resume_interval) and self._controller.is_active():
            #  whileの比較順序は変更しないこと (`is_paused`と`wait_for_resume`の実行間隔を最小化。 )
            pass

        if paused:
            self.on_resumed()

Mixin

class ThreadEventMixin:
    def on_paused(self):
        pass
    def on_resumed(self):
        pass

達成条件

  • イベント呼び出し処理の実装
  • テスト
  • Mixinの実装
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants