from threading import Condition

from timeutil import AwakableSleeper


class ForeverSleeper(AwakableSleeper):
    def __init__(self, when_sleep_condition):
        self.when_sleep_condition = when_sleep_condition

        self.condition = Condition()

    def sleep(self, secs):
        with self.when_sleep_condition:
            self.when_sleep_condition.notify()

        with self.condition:
            self.condition.wait()

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