-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permit
convert
on values in Store
put!
methods
- Loading branch information
Showing
5 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using ConcurrentSim | ||
using ResumableFunctions | ||
using Test | ||
|
||
@resumable function producer(env, queue) | ||
for item in [1,2,3,4] | ||
@info "putting $item at time $(now(env))" | ||
put!(queue, item) | ||
@yield timeout(env, 2) | ||
end | ||
end | ||
@resumable function consumer(env, queue) | ||
@yield timeout(env, 5) | ||
while true | ||
t = @yield take!(queue) | ||
@test isa(t, Float64) | ||
@info "taking $(t) at time $(now(env))" | ||
end | ||
end | ||
|
||
function runsim(storeconstructor) | ||
sim = Simulation() | ||
queue = storeconstructor(sim) | ||
@process producer(sim, queue) | ||
@process consumer(sim, queue) | ||
run(sim, 30) | ||
end | ||
|
||
runsim(sim->DelayQueue{Float64}(sim, 10)) | ||
runsim(sim->QueueStore{Float64}(sim)) | ||
runsim(sim->Store{Float64}(sim)) | ||
|
||
# formatting was different in older versions | ||
VERSION >= v"1.8" && @test_throws "MethodError: Cannot `convert`" runsim(sim->Store{Symbol}(sim)) |