from threading import Condition

from ._AwakableSleeper import AwakableSleeper


class ConditionSleeper(AwakableSleeper):
    def __init__(self):
        self.condition = Condition()

    def sleep(self, secs):
        with self.condition:
            self.condition.wait(secs)

    def wake_up(self):
        with self.condition:
            self.condition.notify_all()
