Untitled

Pasted by zyp on Tue Dec 5 22:29:37 2023 UTC as Python
class _AsyncTrigger:
    def __init__(self, cmd):
        self.cmd = cmd

    def __await__(self):
        yield self.cmd
    
    async def until(self, condition):
        while not (await condition.get()):
            await self


class SimulatorContext:
    def delay(self, interval=None):
        return _AsyncTrigger(Delay(interval))

    def tick(self, domain="sync"):
        return _AsyncTrigger(Tick(domain))

    def changed(self, signal, value=None):
        return _AsyncTrigger(_Changed(signal, value))