File: deadlines.py

package info (click to toggle)
python-waiting 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 132 kB
  • sloc: python: 330; sh: 7; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 788 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
try:
    from flux import current_timeline as time_module
except ImportError:
    import time as time_module


class Deadline(object):

    def is_expired(self):
        raise NotImplementedError()  # pragma: no cover

    def get_num_seconds_remaining(self):
        return None


class Within(Deadline):

    def __init__(self, seconds):
        super(Within, self).__init__()
        self._deadline = time_module.time() + seconds

    def is_expired(self):
        return time_module.time() >= self._deadline

    def get_num_seconds_remaining(self):
        return self._deadline - time_module.time()


class Whenever(Deadline):

    def is_expired(self):
        return False


def make_deadline(seconds):
    if seconds is None:
        return Whenever()
    return Within(seconds)