Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juliapluto/betterfilewatching.jl
FileWatching but based on Deno.watchFs
https://github.com/juliapluto/betterfilewatching.jl
Last synced: about 1 month ago
JSON representation
FileWatching but based on Deno.watchFs
- Host: GitHub
- URL: https://github.com/juliapluto/betterfilewatching.jl
- Owner: JuliaPluto
- License: mit
- Created: 2021-05-22T17:13:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-27T08:08:52.000Z (over 1 year ago)
- Last Synced: 2024-11-09T01:06:13.133Z (about 2 months ago)
- Language: Julia
- Size: 36.1 KB
- Stars: 14
- Watchers: 4
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BetterFileWatching.jl
```julia
watch_folder(f::Function, dir=".")
```Watch a folder recursively for any changes. Includes changes to file contents. A [`FileEvent`](@ref) is passed to the callback function `f`.
```julia
watch_file(f::Function, filename=".")
```Watch a file for changes. A [`FileEvent`](@ref) is passed to the callback function `f`.
# Example
```julia
watch_folder(".") do event
@info "Something changed!" event
end
```You can watch a folder asynchronously, and interrupt the task later:
```julia
watch_task = @async watch_folder(".") do event
@info "Something changed!" event
endsleep(5)
# stop watching the folder
schedule(watch_task, InterruptException(); error=true)
```# Differences with the FileWatching stdlib
`BetterFileWatching.watch_file` is an alternative to `FileWatching.watch_file`. The differences are:
- We offer an additional callback API (`watch_file(::Function, ::String)`, like the examples above), which means that *handling* events does not block *receiving new events*: we keep listening to changes asynchronously while your callback runs.
- BetterFileWatching.jl is just a small wrapper around [`Deno.watchFs`](https://doc.deno.land/builtin/stable#Deno.watchFs), made available through the [Deno_jll](https://github.com/JuliaBinaryWrappers/Deno_jll.jl) package. `Deno.watchFs` is well-tested and widely used.`BetterFileWatching.watch_folder` is an alternative to `FileWatching.watch_folder`. The differences are, in addition to those mentioned above for `watch_file`:
- `BetterFileWatching.watch_folder` works _recursively_, i.e. subfolders are also watched.
- `BetterFileWatching.watch_folder` also watches for changes to the _contents_ of files contained in the folder.---
In fact, `BetterFileWatching.watch_file` and `BetterFileWatching.watch_folder` are actually just the same function! It handles both files and folders.