Skip to content

fs: an event-driven file watch (inotify / FSEvents / ReadDirectoryChangesW) for hot reload #21

Closed

Description

@Sunrisepeak

What

An event-driven file watch in mcpplibs.os::fs: a program says which files or directories to watch and is told when one changes, instead of polling last_write_time.

Why

openmui's development mode reloads an application's TypeScript, views and themes when they are saved (hot reload, live design). The target is save-to-screen ≤ 100 ms at p95. Today the player polls each watched file's modification time every frame (1/60 s) in development; that meets the budget but wakes the program every frame even when nothing changes, and the cost grows with the number of files (a project's imported modules, components, themes).

Shape (a suggestion)

auto w = mcpplibs::os::fs::watcher::open();          // result<watcher>
w->add(path);                                         // a file, or a directory (recursive optional)
auto changed = w->take();                             // non-blocking: the paths changed since the last take
auto changed = w->wait_for(std::chrono::milliseconds); // or wait
int fd = w->native_handle();                          // to join an event loop (where the platform has one)

Backends: inotify (Linux), FSEvents or kqueue (macOS), ReadDirectoryChangesW (Windows); errc::not_supported where there is none (Emscripten), so callers fall back to polling. Editors that save by rename (write a temporary, rename over) should still report the watched path.

Activity

  1. speak-agent commented on Nov 9, 2026

    @speak-agent
    Contributor

    Released in mcpplibs.os 0.4.2 (#22, in mcpp-index): fs::watcher holds names (files and directories, which need not exist yet) and answers which of them changed since the last answer, each once. inotify (Linux), kqueue (macOS) and ReadDirectoryChangesW (Windows) say when to look; each name's stamp, kind and identity say what changed, so every system answers alike. An ok image and Emscripten look when asked. native_handle() is the descriptor an event loop waits upon on Linux and macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions