Skip to content

Commit d51d781

Browse files
authored
Permit convert on values in Store put! methods (#125)
1 parent 13654da commit d51d781

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# News
22

3-
## v1.4.1 - dev
3+
## v1.4.1 - 2024-05-03
44

5+
6+
- Permit stores `put!` methods to cast the value being placed to the type appropriate for the given store.
57
- Added examples to the documentation that were lost around the time of the rewrite for v0.5 in 2018.
68

79
## v1.4.0 - 2023-08-07

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license = "MIT"
55
desc = "A discrete event process oriented simulation framework."
66
authors = ["Ben Lauwens and SimJulia and ConcurrentSim contributors"]
77
repo = "https://github.com/JuliaDynamics/ConcurrentSim.jl.git"
8-
version = "1.4.0"
8+
version = "1.4.1"
99

1010
[deps]
1111
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

src/resources/stores.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ function put!(sto::Store{N, T}, item::N; priority=zero(T)) where {N, T<:Number}
6868
put_ev
6969
end
7070

71+
put!(sto::Store{N, T}, item; priority=zero(T)) where {N, T<:Number} = put!(sto, convert(N, item); priority)
72+
7173
get_any_item(::N) where N = true
7274

7375
function get(sto::Store{N, T, D}, filter::Function=get_any_item; priority=zero(T)) where {N, T<:Number, D}

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREA
3434
@doset "resources_containers"
3535
@doset "resources_containers_deprecated"
3636
@doset "resources_stores"
37+
@doset "resources_stores_cast"
3738
@doset "resources_stores_deprecated"
3839
@doset "resources_fancy_stores"
3940
@doset "resource_priorities"

test/test_resources_stores_cast.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using ConcurrentSim
2+
using ResumableFunctions
3+
using Test
4+
5+
@resumable function producer(env, queue)
6+
for item in [1,2,3,4]
7+
@info "putting $item at time $(now(env))"
8+
put!(queue, item)
9+
@yield timeout(env, 2)
10+
end
11+
end
12+
@resumable function consumer(env, queue)
13+
@yield timeout(env, 5)
14+
while true
15+
t = @yield take!(queue)
16+
@test isa(t, Float64)
17+
@info "taking $(t) at time $(now(env))"
18+
end
19+
end
20+
21+
function runsim(storeconstructor)
22+
sim = Simulation()
23+
queue = storeconstructor(sim)
24+
@process producer(sim, queue)
25+
@process consumer(sim, queue)
26+
run(sim, 30)
27+
end
28+
29+
runsim(sim->DelayQueue{Float64}(sim, 10))
30+
runsim(sim->QueueStore{Float64}(sim))
31+
runsim(sim->Store{Float64}(sim))
32+
33+
# formatting was different in older versions
34+
VERSION >= v"1.8" && @test_throws "MethodError: Cannot `convert`" runsim(sim->Store{Symbol}(sim))

0 commit comments

Comments
 (0)