Skip to content

Commit 6cc18db

Browse files
committed
Change calling conventions for events
1 parent 9c2094d commit 6cc18db

27 files changed

+145
-144
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ julia> Pkg.add("SimJulia")
5656

5757
function datetimetest(sim::Simulation)
5858
println(nowDatetime(sim))
59-
yield(Timeout(sim, Day(2)))
59+
yield(timeout(sim, Day(2)))
6060
println(nowDatetime(sim))
6161
end
6262

@@ -73,7 +73,7 @@ julia> Pkg.add("SimJulia")
7373
b = 1.0
7474
while true
7575
println(now(sim), ": ", a)
76-
yield(Timeout(sim, 1))
76+
yield(timeout(sim, 1))
7777
a, b = b, a+b
7878
end
7979
end
@@ -91,7 +91,7 @@ julia> Pkg.add("SimJulia")
9191
b = 1.0
9292
while true
9393
println(now(sim), ": ", a)
94-
@yield Timeout(sim, 1)
94+
@yield timeout(sim, 1)
9595
a, b = b, a+b
9696
end
9797
end

benchmark/old_processes_MM1.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ using SimJulia, Distributions, BenchmarkTools
33
function exp_source(sim::Simulation, lambd::Float64, server::Resource, mu::Float64)
44
while true
55
dt = rand(Exponential(1/lambd))
6-
yield(Timeout(sim, dt))
6+
yield(timeout(sim, dt))
77
@oldprocess customer(sim, server, mu)
88
end
99
end
1010

1111
function customer(sim::Simulation, server::Resource, mu::Float64)
12-
yield(Request(server))
12+
yield(request(server))
1313
dt = rand(Exponential(1/mu))
14-
yield(Timeout(sim, dt))
15-
yield(Release(server))
14+
yield(timeout(sim, dt))
15+
yield(release(server))
1616
end
1717

1818
function customer2(sim::Simulation, server::Resource, mu::Float64)
1919
request(server) do req
2020
yield(req)
2121
dt = rand(Exponential(1/mu))
22-
yield(Timeout(sim, dt))
22+
yield(timeout(sim, dt))
2323
end
2424
end
2525

benchmark/old_processes_fibonnaci.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function fibonnaci(sim::Simulation)
44
a = 0.0
55
b = 1.0
66
while true
7-
yield(Timeout(sim, 1))
7+
yield(timeout(sim, 1))
88
a, b = b, a+b
99
end
1010
end

benchmark/processes_MM1.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ using ResumableFunctions, SimJulia, Distributions, BenchmarkTools
33
@resumable function exp_source(sim::Simulation, lambd::Float64, server::Resource, mu::Float64)
44
while true
55
dt = rand(Exponential(1 / lambd))
6-
@yield Timeout(sim, dt)
6+
@yield timeout(sim, dt)
77
@process customer(sim, server, mu)
88
end
99
end
1010

1111
@resumable function customer(sim::Simulation, server::Resource, mu::Float64)
12-
@yield Request(server)
12+
@yield request(server)
1313
dt = rand(Exponential(1 / mu))
14-
@yield Timeout(sim, dt)
15-
@yield Release(server)
14+
@yield timeout(sim, dt)
15+
@yield release(server)
1616
end
1717

1818
function test_mm1(n::Float64)

benchmark/processes_fibonnaci.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using ResumableFunctions, SimJulia, BenchmarkTools
44
a = 0.0
55
b = 1.0
66
while true
7-
@yield Timeout(sim, 1)
7+
@yield timeout(sim, 1)
88
a, b = b, a+b
99
end
1010
end

docs/src/examples/ross.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ const G = Exponential(MU)
3232
3333
@resumable function machine(env::Environment, repair_facility::Resource, spares::Store{Process})
3434
while true
35-
try @yield Timeout(env, Inf) end
36-
@yield Timeout(env, rand(F))
37-
get_spare = Get(spares)
38-
@yield get_spare | Timeout(env)
35+
try @yield timeout(env, Inf) end
36+
@yield timeout(env, rand(F))
37+
get_spare = get(spares)
38+
@yield get_spare | timeout(env)
3939
if state(get_spare) != SimJulia.idle
4040
@yield interrupt(value(get_spare))
4141
else
4242
throw(SimJulia.StopSimulation("No more spares!"))
4343
end
44-
@yield Request(repair_facility)
45-
@yield Timeout(env, rand(G))
46-
@yield Release(repair_facility)
47-
@yield Put(spares, active_process(env))
44+
@yield request(repair_facility)
45+
@yield timeout(env, rand(G))
46+
@yield release(repair_facility)
47+
@yield put(spares, active_process(env))
4848
end
4949
end
5050
@@ -53,12 +53,12 @@ end
5353
for i in 1:N
5454
push!(procs, @process machine(env, repair_facility, spares))
5555
end
56-
@yield Timeout(env)
56+
@yield timeout(env)
5757
for proc in procs
5858
@yield interrupt(proc)
5959
end
6060
for i in 1:S
61-
@yield Put(spares, @process machine(env, repair_facility, spares))
61+
@yield put(spares, @process machine(env, repair_facility, spares))
6262
end
6363
end
6464

docs/src/guides/basics.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using ResumableFunctions
2121
using SimJulia
2222
2323
@resumable function example(env::Environment)
24-
event = Timeout(env, 1, value=42)
24+
event = timeout(env, 1, value=42)
2525
value = @yield event
2626
println("now=", now(env), ", value=", value)
2727
end
@@ -35,11 +35,11 @@ run(sim)
3535
now=1.0, value=42
3636
```
3737

38-
The `example` process function above first creates a `Timeout` event. It passes the environment, a delay, and a value to it. The `Timeout` schedules itself at `now + delay` (that’s why the environment is required); other event types usually schedule themselves at the current simulation time.
38+
The `example` process function above first creates a `timeout` event. It passes the environment, a delay, and a value to it. The `timeout` schedules itself at `now + delay` (that’s why the environment is required); other event types usually schedule themselves at the current simulation time.
3939

40-
The process function then yields the event and thus gets suspended. It is resumed, when SimJulia processes the `Timeout` event. The process function also receives the event’s value (42) – this is, however, optional, so `@yield event` would have been okay if the you were not interested in the value or if the event had no value at all.
40+
The process function then yields the event and thus gets suspended. It is resumed, when SimJulia processes the `timeout` event. The process function also receives the event’s value (42) – this is, however, optional, so `@yield event` would have been okay if the you were not interested in the value or if the event had no value at all.
4141

42-
Finally, the process function prints the current simulation time (that is accessible via the `now` function) and the `Timeout`’s value.
42+
Finally, the process function prints the current simulation time (that is accessible via the `now` function) and the `timeout`’s value.
4343

4444
If all required process functions are defined, you can instantiate all objects for your simulation. In most cases, you start by creating an instance of `Environment`, e.g. a `Simulation`, because you’ll need to pass it around a lot when creating everything else.
4545

docs/src/guides/environments.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030

3131
- Instead of passing a number as second argument to `run`, you can also pass any event to it. `run` will then return when the event has been processed.
3232

33-
Assuming that the current time is 0, `run(env, Timeout(env, 5))` is equivalent to `run(env, 5)`.
33+
Assuming that the current time is 0, `run(env, timeout(env, 5))` is equivalent to `run(env, 5)`.
3434

3535
You can also pass other types of events (remember, that a `Process` is an event, too):
3636

@@ -39,7 +39,7 @@ using ResumableFunctions
3939
using SimJulia
4040
4141
@resumable function my_process(env::Environment)
42-
@yield Timeout(env, 1)
42+
@yield timeout(env, 1)
4343
"Monty Python's Flying Circus"
4444
end
4545
@@ -63,14 +63,14 @@ end
6363

6464
## State access
6565

66-
The environment allows you to get the current simulation time via the function `now`. The simulation time is a number without unit and is increased via `Timeout` events.
66+
The environment allows you to get the current simulation time via the function `now`. The simulation time is a number without unit and is increased via `timeout` events.
6767

6868
By default, the simulation starts at time 0, but you can pass an `initial_time` to the `Simulation` constructor to use something else.
6969

7070
Note
7171

7272
!!! note
73-
Although the simulation time is technically unitless, you can pretend that it is, for example, in milliseconds and use it like a timestamp returned by `Base.Dates.datetime2epochm` to calculate a date or the day of the week. The `Simulation` constructor and the `run` function accept as argument a `Base.Dates.DateTime` and the `Timeout` constructor a `Base.Dates.Delay`. Together with the convenience function `nowDateTime` a simulation can transparantly schedule its events in seconds, minutes, hours, days, ...
73+
Although the simulation time is technically unitless, you can pretend that it is, for example, in milliseconds and use it like a timestamp returned by `Base.Dates.datetime2epochm` to calculate a date or the day of the week. The `Simulation` constructor and the `run` function accept as argument a `Base.Dates.DateTime` and the `timeout` constructor a `Base.Dates.Delay`. Together with the convenience function `nowDateTime` a simulation can transparantly schedule its events in seconds, minutes, hours, days, ...
7474

7575
The function `active_process` is comparable to `Base.Libc.getpid` and returns the current active `Process`. If no process is active, a `NullException` is thrown. A process is active when its process function is being executed. It becomes inactive (or suspended) when it yields an event.
7676

@@ -90,7 +90,7 @@ julia> @resumable function my_proc(env::Environment)
9090
while true
9191
println(active_process(env))
9292
subfunc(env)
93-
@yield Timeout(env, 1)
93+
@yield timeout(env, 1)
9494
end
9595
end
9696
my_proc (generic function with 1 method)
@@ -122,7 +122,7 @@ A generator function can have a return value:
122122

123123
```julia
124124
@resumable function my_proc(env::Environment)
125-
@yield Timeout(sim, 1)
125+
@yield timeout(sim, 1)
126126
150
127127
end
128128
```

docs/src/guides/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SimJulia includes an extensive set of event types for various purposes. All of them are descendants of `AbstractEvent`. Here the following events are discussed:
44

55
- `Event`
6-
- `Timeout`
6+
- `timeout`
77
- `Operator`
88

99
The guide to resources describes the various resource events.

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ julia> using SimJulia
1616
julia> @resumable function clock(sim::Simulation, name::String, tick::Float64)
1717
while true
1818
println(name, " ", now(sim))
19-
@yield Timeout(sim, tick)
19+
@yield timeout(sim, tick)
2020
end
2121
end
2222
clock (generic function with 1 method)

0 commit comments

Comments
 (0)