There's a Nim binding for the fswatch C-library, to watch for file system events https://github.com/paul-nameless/nim-fswatch
Would it be possible to use it with the async HTTP server?
I wrote example but it's not working with async server properly. If you open the HTTP page, it just waits and never respond.
import std/[httpcore, asynchttpserver, asyncnet, asyncdispatch]
import libfswatch, libfswatch/fswatch
# DB ----------------------------------------------------------
type DB = ref object
events: seq[string]
let db = DB()
# HTTP Server -------------------------------------------------
proc handler(req: Request): Future[void] {.async, gcsafe.} =
let content = $(db[])
await req.respond(Http200, content)
var server = new_async_http_server()
async_check server.serve(Port(4000), handler, "localhost")
# FS Watch ----------------------------------------------------
proc callback(event: fsw_cevent, event_num: cuint) =
db.events.add $(event.path)
echo $(db[])
var mon = newMonitor()
mon.addPath(".")
mon.setCallback(callback)
mon.start() # <= Blocking call that seems to break async
run_forever() # <= This line never called
Thanks, I checked that thread, but seems like the async library https://github.com/Vindaar/fsmonitor2 supports linux only, I'm using mac os.
P.S. There's also bruteforce option, diff path tree periodically, going to use it for now :)