How to use the aiozk.WatchEvent.DELETED function in aiozk

To help you get started, we’ve selected a few aiozk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github micro-fan / aiozk / aiozk / recipes / barrier.py View on Github external
async def wait(self, timeout=None):
        barrier_lifted = self.client.wait_for_events(
            [WatchEvent.DELETED], self.path
        )

        exists = await self.client.exists(path=self.path, watch=True)
        if not exists:
            return

        try:
            if timeout:
                await asyncio.wait_for(barrier_lifted, timeout)
            else:
                await barrier_lifted
        except asyncio.TimeoutError:
            raise exc.TimeoutError
github micro-fan / aiozk / aiozk / recipes / children_watcher.py View on Github external
from aiozk import WatchEvent

from .base_watcher import BaseWatcher


class ChildrenWatcher(BaseWatcher):

    watched_events = [WatchEvent.CHILDREN_CHANGED, WatchEvent.DELETED]

    async def fetch(self, path):
        children = await self.client.get_children(path=path, watch=True)
        return children
github micro-fan / aiozk / aiozk / recipes / data_watcher.py View on Github external
from aiozk import WatchEvent
from aiozk.exc import NoNode

from .base_watcher import BaseWatcher


class DataWatcher(BaseWatcher):

    watched_events = [WatchEvent.DATA_CHANGED, WatchEvent.DELETED]

    def __init__(self, *args, wait_for_create=False, **kwargs):
        super().__init__(*args, **kwargs)

        if wait_for_create:
            self.watched_events.append(WatchEvent.CREATED)

    async def fetch(self, path):
        # exists() gives create, delete, and update watches
        watch_via_exists = WatchEvent.CREATED in self.watched_events
        if watch_via_exists:
            exists = await self.client.exists(path, watch=True)
            if not exists:
                raise NoNode
        data = await self.client.get_data(path=path, watch=not watch_via_exists)
        return data
github micro-fan / aiozk / aiozk / recipes / sequential.py View on Github external
async def wait_on_sibling(self, sibling, timeout=None):
        log.debug("Waiting on sibling %s", sibling)

        path = self.sibling_path(sibling)

        unblocked = self.client.wait_for_events([WatchEvent.DELETED], path)

        exists = await self.client.exists(path=path, watch=True)
        if not exists:
            unblocked.set_result(None)

        try:
            if timeout:
                await asyncio.wait_for(unblocked, timeout)
            else:
                await unblocked
        except asyncio.TimeoutError:
            raise exc.TimeoutError