File: trigger.py

package info (click to toggle)
pytest-watcher 0.4.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 856 kB
  • sloc: python: 925; makefile: 28; sh: 13
file content (30 lines) | stat: -rw-r--r-- 629 bytes parent folder | download
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
import threading
import time


class Trigger:
    _value: float
    _lock: threading.Lock

    def __init__(self, delay: float = 0.0):
        self._lock = threading.Lock()
        self._value = 0
        self._delay = delay

    def emit(self):
        with self._lock:
            self._value = time.time() + self._delay

    def emit_now(self):
        with self._lock:
            self._value = time.time()

    def is_active(self):
        return self._value != 0

    def release(self):
        with self._lock:
            self._value = 0

    def check(self):
        return self._value > 0 and time.time() > self._value