Skip to content

Commit

Permalink
Enable watching directories
Browse files Browse the repository at this point in the history
Fixes #470
  • Loading branch information
timholy committed May 25, 2020
1 parent b35fd85 commit 9969c59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Revise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ You can use the return value `key` to remove the callback later
to `Revise.add_callback` with `key=key`.
"""
function add_callback(f, files, modules=nothing; key=gensym())
fix_trailing(path) = isdir(path) ? joinpath(path, "") : path # insert a trailing '/' if missing, see https://github.com/timholy/Revise.jl/issues/470#issuecomment-633298553

remove_callback(key)

files = map(abspath, files)
files = map(fix_trailing, map(abspath, files))
init_watching(files)

if modules !== nothing
Expand Down Expand Up @@ -928,7 +930,7 @@ includet(file::AbstractString) = includet(Main, file)
entr(f, files; postpone=false, pause=0.02)
entr(f, files, modules; postpone=false, pause=0.02)
Execute `f()` whenever files listed in `files`, or code in `modules`, updates.
Execute `f()` whenever files or directories listed in `files`, or code in `modules`, updates.
`entr` will process updates (and block your command line) until you press Ctrl-C.
Unless `postpone` is `true`, `f()` will be executed also when calling `entr`,
regardless of file changes. The `pause` is the period (in seconds) that `entr`
Expand Down
29 changes: 29 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2949,6 +2949,35 @@ do_test("entr") && @testset "entr" begin
@test isa(err, LoadError)
@test err.error.msg == "stop"
end

# Watch directories (#470)
dn = joinpath(tempdir(), randtmp())
mkdir(dn)
fn = joinpath(dn, "trigger.txt")
open(fn, "w") do io
println(io, "blank")
end
counter = Ref(0)
stop = Ref(false)
try
@sync begin
@async begin
entr([dn]) do
counter[] += 1
stop[] && error("stopping")
end
end
sleep(mtimedelay)
touch(fn)
sleep(mtimedelay)
@test counter[] == 1
stop[] = true
touch(fn)
sleep(mtimedelay)
end
catch
@test counter[] == 2
end
end

const A354_result = Ref(0)
Expand Down

0 comments on commit 9969c59

Please sign in to comment.