Skip to content

Commit 8e72fe9

Browse files
committed
deprecate ConcurrentSim.put in favor of Base.put!
1 parent 91a9809 commit 8e72fe9

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

docs/src/examples/Latency.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ In this example we show how to separate the time delay between processes from th
1010
```julia
1111
using ConcurrentSim
1212
using ResumableFunctions
13-
import ConcurrentSim.put
14-
import Base.get
13+
import Base: put!, get
1514
```
1615

1716
### Define Constants
@@ -46,15 +45,15 @@ The latency function is a generator which yields two events: first a `timeout` t
4645
```julia
4746
@resumable function latency(env::Simulation, cable::Cable, value::String)
4847
@yield timeout(cable.env, cable.delay)
49-
@yield put(cable.store, value)
48+
@yield put!(cable.store, value)
5049
end;
5150
```
5251

53-
The `put` and `get` functions allow interaction with the cable (note that these are not `@resumable` because they need to return the result of the operation and not the operation itself).
52+
The `put!` and `get` functions allow interaction with the cable (note that these are not `@resumable` because they need to return the result of the operation and not the operation itself).
5453

5554

5655
```julia
57-
function put(cable::Cable, value::String)
56+
function put!(cable::Cable, value::String)
5857
@process latency(cable.env, cable, value) # results in the scheduling of all events generated by latency
5958
end
6059

@@ -71,7 +70,7 @@ The `sender` and `receiver` generators yield events to the simulator.
7170
while true
7271
@yield timeout(env, SEND_PERIOD)
7372
value = "sender sent this at $(now(env))"
74-
put(cable, value)
73+
put!(cable, value)
7574
end
7675
end
7776

docs/src/examples/ross.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const G = Exponential(MU)
4747
@yield request(repair_facility)
4848
@yield timeout(env, rand(rng, G))
4949
@yield release(repair_facility)
50-
@yield put(spares, active_process(env))
50+
@yield put!(spares, active_process(env))
5151
end
5252
end
5353
@@ -58,7 +58,7 @@ end
5858
end
5959
for i in 1:S
6060
proc = @process machine(env, repair_facility, spares)
61-
@yield put(spares, proc)
61+
@yield put!(spares, proc)
6262
end
6363
end
6464

src/ConcurrentSim.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ module ConcurrentSim
77
using Dates
88
using ResumableFunctions
99

10-
import Base.run, Base.isless, Base.show, Base.yield, Base.get
11-
import Base.(&), Base.(|)
12-
import Dates.now
10+
import Base: run, isless, show, yield, get, put!, &, |
11+
import Dates: now
1312

1413
export AbstractEvent, Environment, value, state, environment
1514
export Event, succeed, fail, @callback, remove_callback
@@ -18,7 +17,7 @@ module ConcurrentSim
1817
export @resumable, @yield
1918
export AbstractProcess, Simulation, run, now, active_process, StopSimulation
2019
export Process, @process, interrupt
21-
export Container, Resource, Store, put, get, request, release, cancel
20+
export Container, Resource, Store, put!, get, request, release, cancel
2221
export nowDatetime
2322

2423
include("base.jl")
@@ -30,4 +29,5 @@ module ConcurrentSim
3029
include("resources/containers.jl")
3130
include("resources/stores.jl")
3231
include("utils/time.jl")
32+
include("deprecated.jl")
3333
end

src/deprecated.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Base.@deprecate put(args...) put!(args...)

src/resources/containers.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ end
2222

2323
const Resource = Container{Int}
2424

25-
function put(con::Container{N}, amount::N; priority::Int=0) where N<:Real
25+
function put!(con::Container{N}, amount::N; priority::Int=0) where N<:Real
2626
put_ev = Put(con.env)
2727
con.put_queue[put_ev] = ContainerKey(priority, con.seid+=one(UInt), amount)
2828
@callback trigger_get(put_ev, con)
2929
trigger_put(put_ev, con)
3030
put_ev
3131
end
3232

33-
request(res::Resource; priority::Int=0) = put(res, 1; priority=priority)
33+
request(res::Resource; priority::Int=0) = put!(res, 1; priority=priority)
3434

3535
function get(con::Container{N}, amount::N; priority::Int=0) where N<:Real
3636
get_ev = Get(con.env)

src/resources/stores.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mutable struct Store{T} <: AbstractResource
2424
end
2525
end
2626

27-
function put(sto::Store{T}, item::T; priority::Int=0) where T
27+
function put!(sto::Store{T}, item::T; priority::Int=0) where T
2828
put_ev = Put(sto.env)
2929
sto.put_queue[put_ev] = StorePutKey{T}(priority, sto.seid+=one(UInt), item)
3030
@callback trigger_get(put_ev, sto)

test/test_resources_containers.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ end
4646
amount = 2*rand()
4747
println("$(now(sim)), producer is offering $amount")
4848
@yield timeout(sim, 1.0*rand())
49-
@yield put(con, amount)
49+
@yield put!(con, amount)
5050
level = con.level
5151
println("$(now(sim)), producer is being served, level is ", level)
5252
delay = 5.0*rand()
@@ -59,3 +59,23 @@ con = Container(sim, 10.0; level=5.0)
5959
@process my_consumer(sim, con)
6060
@process my_producer(sim, con)
6161
run(sim)
62+
63+
64+
@resumable function my_producer_old_put(sim::Simulation, con::Container) # from before deprecating put
65+
for i in 1:10
66+
amount = 2*rand()
67+
println("$(now(sim)), producer is offering $amount")
68+
@yield timeout(sim, 1.0*rand())
69+
@yield put(con, amount)
70+
level = con.level
71+
println("$(now(sim)), producer is being served, level is ", level)
72+
delay = 5.0*rand()
73+
@yield timeout(sim, delay)
74+
end
75+
end
76+
77+
sim = Simulation()
78+
con = Container(sim, 10.0; level=5.0)
79+
@process my_consumer(sim, con)
80+
@process my_producer_old_put(sim, con)
81+
run(sim)

test/test_resources_stores.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717
@resumable function my_producer(sim::Simulation, sto::Store)
1818
for j in 1:10
1919
println("$(now(sim)), producer is offering object $j")
20-
@yield put(sto, StoreObject(j))
20+
@yield put!(sto, StoreObject(j))
2121
println("$(now(sim)), producer is being served")
2222
@yield timeout(sim, 2*rand())
2323
end

0 commit comments

Comments
 (0)