Skip to content

Commit

Permalink
DEPRECATE has_event => pull_event
Browse files Browse the repository at this point in the history
  • Loading branch information
josePereiro committed Sep 25, 2024
1 parent 4b9ed9c commit 760da08
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let

# This will run if Main.__glob changed from the last update
# The bang indicates that `update!(e, :__glob)` will be called
if has_event!(e, :__glob)
if pull_event!(e, :__glob)
println("[", it, "] event detected!!!")
else
println("[", it, "] nothing to do!!!")
Expand Down
36 changes: 31 additions & 5 deletions src/AbstractEvent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,26 @@ Base.get(f::Function, e::AbstractEvent, key) = get(f, states(e), key)
"""
Returns true if the event happened.
It do not update the handler state (see bang version).
DEPRECATED
"""
has_event

has_event(e::AbstractEvent, args...) = trigger(e, old_state(e, args...), new_state(e, args...))

"""
Returns true if the event happened.
It do not update the handler state (see bang version).
"""
pull_event

pull_event(e::AbstractEvent, args...) = trigger(e, old_state(e, args...), new_state(e, args...))

@deprecate has_event(x...) pull_event(x...) true

"""
Returns true if the event happened.
Additionally, it will call `update!` over the handler (only if `has_event` triggered).
DEPRECATED
"""
has_event!

Expand All @@ -49,22 +60,37 @@ function has_event!(e::AbstractEvent, args...)
return flag
end


"""
Returns true if the event happened.
Additionally, it will call `update!` over the handler (only if `pull_event` triggered).
"""
Executes `f()` if `has_event` returns true.
pull_event!

function pull_event!(e::AbstractEvent, args...)
flag = pull_event(e, args...)
flag && update!(e, args...)
return flag
end

@deprecate has_event!(x...) pull_event!(x...) true

"""
Executes `f()` if `pull_event` returns true.
Returns the results of `f()` or nothing.
"""
on_event

on_event(f::Function, e::AbstractEvent, args...) = (has_event(e, args...) ? f() : nothing)
on_event(f::Function, e::AbstractEvent, args...) = (pull_event(e, args...) ? f() : nothing)

"""
Executes `f()` if `has_event` returns true.
Additionally, it will call `update!` over the handler (only if `has_event` triggered).
Executes `f()` if `pull_event` returns true.
Additionally, it will call `update!` over the handler (only if `pull_event` triggered).
Returns the results of `f()` or nothing.
"""
on_event!

function on_event!(f::Function, e::AbstractEvent, args...)
flag = has_event!(e, args...)
flag = pull_event!(e, args...)
return flag ? f() : nothing
end
2 changes: 1 addition & 1 deletion src/EasyEvents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module EasyEvents
include("AbstractEvent.jl")
export AbstractEvent
export old_state, new_state, update!, reset!, trigger, states, istraking
export has_event, has_event!, on_event, on_event!
export has_event, has_event!,pull_event, pull_event!, on_event, on_event!

include("CustomEvent.jl")
export CustomEvent
Expand Down
2 changes: 1 addition & 1 deletion src/FileContentEvent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end

function _dft_file_content_new_state(e::CustomEvent, file::String)
mtime_event = _file_content_mtime_event(e)
if has_event!(mtime_event, file)
if pull_event!(mtime_event, file)
# Recompute only is file was modify (better performance)
# And cached
hash_ = _up_file_content_hash_cache!(e, file)
Expand Down
2 changes: 1 addition & 1 deletion test/FileContentEvent_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
trigger_at = [3, 4, 5]
for it in 1:10
touch(file)
if has_event!(e, file)
if pull_event!(e, file)
println(basename(file), " changed!!!")
events_count += 1
end
Expand Down
2 changes: 1 addition & 1 deletion test/FileMTimeEvent_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
events_count = 0
trigger_at = [3, 4, 5]
for it in 1:10
if has_event!(e ,file)
if pull_event!(e ,file)
println(basename(file), " changed!!!")
events_count += 1
end
Expand Down
2 changes: 1 addition & 1 deletion test/FileSizeEvent_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
events_count = 0
trigger_at = [3, 4, 5]
for it in 1:10
if has_event!(e ,file)
if pull_event!(e ,file)
println(basename(file), " changed!!!")
events_count += 1
end
Expand Down
2 changes: 1 addition & 1 deletion test/PropertyChangedEvent_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
trigger_at = [3, 4, 5]
for it in 1:10

if has_event!(e, :__glob)
if pull_event!(e, :__glob)
println(:__glob, " changed!!!")
events_count += 1
end
Expand Down

0 comments on commit 760da08

Please sign in to comment.