Skip to content

Feat: Option to yield immediately when watcher starts #358

Description

@FelixFourcolor

I think it's a common pattern to first run a function unconditionally, then re-run every time a file changes (e.g. a live web server that refreshes when code changes).

You can do this:

foo()
for _ in watchfiles.watch(file):
    foo()

The issue with this is, changes that happen during the first run won't be registered. Currently there isn't a nice way to express this pattern.


Suggestion: Add this option

def watch(..., yield_on_start: bool):
    with RustNotify(...):
        if yield_on_start:
            yield set()
        while True:
            ...  # remaining code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions