Skip to content

Commit 80302fa

Browse files
committed
Add Interrupt and Initialize as events
1 parent 1102b50 commit 80302fa

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

docs/src/examples/ross.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ const G = Exponential(MU)
3636
@yield Timeout(env, rand(F))
3737
get_spare = Get(spares)
3838
@yield get_spare | Timeout(env)
39-
state(get_spare) != SimJulia.idle ? interrupt(value(get_spare)) : throw(SimJulia.StopSimulation("No more spares!"))
39+
if state(get_spare) != SimJulia.idle
40+
interrupt(value(get_spare))
41+
else
42+
throw(SimJulia.StopSimulation("No more spares!"))
43+
end
4044
@yield Request(repair_facility)
4145
@yield Timeout(env, rand(G))
4246
@yield Release(repair_facility)

src/events.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ struct Timeout <: AbstractEvent
2121
end
2222
end
2323

24+
struct Initialize <: AbstractEvent
25+
bev :: BaseEvent
26+
function Initialize(env::Environment)
27+
schedule(new(BaseEvent(env)))
28+
end
29+
end
30+
31+
struct Interrupt <: AbstractEvent
32+
bev :: BaseEvent
33+
function Interrupt(env::Environment)
34+
new(BaseEvent(env))
35+
end
36+
end
37+
2438
function run(env::Environment, until::Number=typemax(Float64))
2539
run(env, Timeout(env, until-now(env)))
26-
end
40+
end

src/processes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mutable struct Process <: DiscreteProcess
77
cor = new()
88
cor.bev = BaseEvent(env)
99
cor.fsmi = func(env, args...)
10-
cor.target = Timeout(env)
10+
cor.target = Initialize(env)
1111
cor.resume = @callback execute(cor.target, cor)
1212
cor
1313
end
@@ -38,7 +38,7 @@ end
3838
function interrupt(proc::Process, cause::Any=nothing)
3939
if !done(proc.fsmi)
4040
remove_callback(proc.resume, proc.target)
41-
proc.target = Timeout(environment(proc); priority=typemax(Int8), value=InterruptException(proc, cause))
41+
proc.target = schedule(Interrupt(environment(proc)); priority=typemax(Int8), value=InterruptException(proc, cause))
4242
proc.resume = @callback execute(proc.target, proc)
4343
end
4444
end

0 commit comments

Comments
 (0)