Skip to content

Commit

Permalink
priority for all Events is restored to Int; remove type signature on …
Browse files Browse the repository at this point in the history
…kwargs (#96)
  • Loading branch information
hdavid16 authored Aug 3, 2023
1 parent bb72add commit b8de238
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Private = false
```

```@docs
unlock(res::Resource; priority::Number=0)
take!(sto::Store, filter::Function=get_any_item; priority::Int=0)
unlock(res::Resource; priority=0)
take!(sto::Store, filter::Function=get_any_item; priority=0)
```
4 changes: 2 additions & 2 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ function remove_callback(cb::Function, ev::AbstractEvent)
i != 0 && deleteat!(ev.bev.callbacks, i)
end

function schedule(ev::AbstractEvent, delay::Number=0; priority::Number=0, value::Any=nothing)
function schedule(ev::AbstractEvent, delay::Number=0; priority=0, value=nothing)
state(ev) === processed && throw(EventProcessed(ev))
env = environment(ev)
bev = ev.bev
bev.value = value
env.heap[bev] = EventKey(now(env) + delay, priority, env.sid+=one(UInt))
env.heap[bev] = EventKey(now(env) + delay, Int(priority), env.sid+=one(UInt))
bev.state = scheduled
ev
end
Expand Down
12 changes: 6 additions & 6 deletions src/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ struct Event <: AbstractEvent
end
end

function succeed(ev::Event; priority::Number=0, value::Any=nothing) :: Event
function succeed(ev::Event; priority=0, value=nothing) :: Event
state(ev) !== idle && throw(EventNotIdle(ev))
schedule(ev; priority=priority, value=value)
schedule(ev; priority=Int(priority), value)
end

function fail(ev::Event, exc::Exception; priority::Number=0) :: Event
succeed(ev; priority=priority, value=exc)
function fail(ev::Event, exc::Exception; priority=0) :: Event
succeed(ev; priority=Int(priority), value=exc)
end

struct Timeout <: AbstractEvent
Expand All @@ -21,8 +21,8 @@ struct Timeout <: AbstractEvent
end
end

function timeout(env::Environment, delay::Number=0; priority::Number=0, value::Any=nothing)
schedule(Timeout(env), delay; priority=priority, value=value)
function timeout(env::Environment, delay::Number=0; priority=0, value::Any=nothing)
schedule(Timeout(env), delay; priority=Int(priority), value)
end

function run(env::Environment, until::Number=Inf)
Expand Down
2 changes: 1 addition & 1 deletion src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function check(ev::AbstractEvent, op::Operator, event_state_values::Dict{Abstrac
end
elseif state(op) === scheduled
if isa(val, Exception)
schedule(op; priority=Inf, value=val)
schedule(op; priority=typemax(Int), value=val)
else
event_state_values[ev] = StateValue(state(ev), val)
end
Expand Down
6 changes: 3 additions & 3 deletions src/processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ end
function interrupt(proc::Process, cause::Any=nothing)
env = environment(proc)
if proc.fsmi._state !== 0xff
proc.target isa Initialize && schedule(proc.target; priority=Inf)
target = schedule(Interrupt(env); priority=Inf, value=InterruptException(active_process(env), cause))
proc.target isa Initialize && schedule(proc.target; priority=typemax(Int))
target = schedule(Interrupt(env); priority=typemax(Int), value=InterruptException(active_process(env), cause))
@callback execute_interrupt(target, proc)
end
timeout(env; priority=Inf)
timeout(env; priority=typemax(Int))
end
4 changes: 2 additions & 2 deletions src/simulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ end

struct EmptySchedule <: Exception end

struct EventKey{N<:Number}
struct EventKey
time :: Float64
priority :: N
priority :: Int
id :: UInt
end

Expand Down
4 changes: 2 additions & 2 deletions src/utils/time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ function run(env::Environment, until::DateTime)
run(env, Dates.datetime2epochms(until))
end

function timeout(env::Environment, delay::Period; priority::Number=0, value::Any=nothing)
function timeout(env::Environment, delay::Period; priority=0, value=nothing)
time = now(env)
del = Dates.datetime2epochms(Dates.epochms2datetime(time)+delay)-time
timeout(env, del; priority=priority, value=value)
timeout(env, del; priority=Int(priority), value)
end

function nowDatetime(env::Environment)
Expand Down

0 comments on commit b8de238

Please sign in to comment.