A WatchBackend on the operating system's change notification,
through watchfiles (the watch extra); without the extra it leaves
every path to the file system. LiveFileSystem uses it when no
provided backend takes the path.
Functions#
register#
register(path, info, *, recursive, on_ready) -> Stream[WatchEvent, PlatformError] | None| Parameter | Type | Description |
|---|---|---|
path | str | |
info | FileInfo | |
recursive | bool | |
on_ready | Callable[[], None] | None |
Returns Stream[WatchEvent, PlatformError] | None
def register(
self,
path: str,
info: FileInfo,
*,
recursive: bool,
on_ready: Callable[[], None] | None,
) -> Stream[WatchEvent, PlatformError] | None:
notify = _rust_notify()
if notify is None:
return None
directory = path if info.type == "Directory" else os.path.dirname(path) or os.curdir
def make() -> Generator[
Effect[Any, PlatformError, Any], Any, Stream[WatchEvent, PlatformError]
]:
watcher = yield from acquire_release(
_Watcher(path, directory, recursive=recursive).start(notify),
lambda watcher, _exit: watcher.stop(),
)
if on_ready is not None:
yield from sync(on_ready)
return stream_.from_pull(succeed(watcher.take()))
return stream_.unwrap(gen(make))