Skip to content

Commit

Permalink
Merge pull request #308 from mlhetland/master
Browse files Browse the repository at this point in the history
Rewrite, postpone and pause
  • Loading branch information
timholy authored May 23, 2019
2 parents e5da960 + 69465c3 commit 580e991
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Revise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -655,11 +655,16 @@ end
includet(file::AbstractString) = includet(Main, file)

"""
entr(f, files)
entr(f, files, modules)
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.
`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`
will wait between being triggered and actually calling `f()`, to handle
clusters of modifications, such as those produced by saving files in certain
text editors.
# Example
Expand All @@ -671,7 +676,7 @@ end
This will print "update" every time `"/tmp/watched.txt"` or any of the code defining
`Pkg1` or `Pkg2` gets updated.
"""
function entr(f::Function, files, modules=nothing)
function entr(f::Function, files, modules=nothing; postpone=false, pause=0.02)
files = collect(files) # because we may add to this list
if modules !== nothing
for mod in modules
Expand All @@ -685,12 +690,13 @@ function entr(f::Function, files, modules=nothing)
active = true
try
@sync begin
postpone || f()
for file in files
waitfor = isdir(file) ? watch_folder : watch_file
@async while active
ret = waitfor(file, 1)
ret.renamed && break
if active && ret.changed
if active && (ret.changed || ret.renamed)
sleep(pause)
revise()
f()
end
Expand Down

0 comments on commit 580e991

Please sign in to comment.