import time
from threading import Condition

from timeutil import AwakableSleeper
from ._NoSleeper import NoSleeper
from ._ClockStub import ClockStub


class AwakableNoSleeper(NoSleeper, AwakableSleeper):
    def __init__(self, clock_to_update: ClockStub = None):
        super().__init__(clock_to_update=clock_to_update)
        self.c = Condition()

    def hibernate(self, secs):
        with self.c:
            self.c.wait(timeout=secs)
        time.sleep(0)
        return

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

        time.sleep(0)
