Skip to content

Instantly share code, notes, and snippets.

@ktbarrett
Created March 9, 2022 17:37
Show Gist options
  • Save ktbarrett/9f1fc616db8b68a39082fd4103d324e4 to your computer and use it in GitHub Desktop.
Save ktbarrett/9f1fc616db8b68a39082fd4103d324e4 to your computer and use it in GitHub Desktop.
from typing import Awaitable, Generic, TypeVar
from cocotb.triggers import Event
T = TypeVar("T")
class Signal(Generic[T]):
def __init__(self, __init_value: T) -> None:
self._value = __init_value
self._last_value = __init_value
self._event = Event()
@property
def value(self) -> T:
return self._value
@value.setter
def value(self, __value) -> None:
self._value = __value
self._event.set()
@property
def last_value(self) -> T:
return self._last_value
@property
def event(self) -> Awaitable[None]:
self._event.clear()
return self._event.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment