Skip to content

Add TapedTask type annotations to storage[:tapedtask] #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 20, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/tapedtask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ struct TapedTask
end
end

function producer()
ttask = current_task().storage[:tapedtask]::TapedTask
if length(ttask.produced_val) > 0
val = pop!(ttask.produced_val)
put!(ttask.produce_ch, val)
take!(ttask.consume_ch) # wait for next consumer
end
return nothing
end

function wrap_task(tf, produce_ch, consume_ch, args...)
try
producer = () -> begin
ttask = current_task().storage[:tapedtask]
if length(ttask.produced_val) > 0
val = pop!(ttask.produced_val)
put!(ttask.produce_ch, val)
take!(ttask.consume_ch) # wait for next consumer
end
end
tf(args...; callback=producer)
catch e
bt = catch_backtrace()
Expand Down Expand Up @@ -100,13 +102,14 @@ end
ct.storage === nothing && return false
haskey(ct.storage, :tapedtask) || return false
# check if we are recording a tape
isempty(ct.storage[:tapedtask].tf.tape) && return false
ttask = ct.storage[:tapedtask]::TapedTask
isempty(ttask.tf.tape) && return false
return true
end

function produce(val)
is_in_tapedtask() || return nothing
ttask = current_task().storage[:tapedtask]
ttask = current_task().storage[:tapedtask]::TapedTask
length(ttask.produced_val) > 1 &&
error("There is a produced value which is not consumed.")
push!(ttask.produced_val, val)
Expand Down Expand Up @@ -157,7 +160,8 @@ Base.IteratorEltype(::Type{TapedTask}) = Base.EltypeUnknown()
function Base.copy(t::TapedTask)
tf = copy(t.tf)
new_t = TapedTask(tf)
new_t.task.storage = copy(t.task.storage)
storage = t.task.storage::IdDict{Any,Any}
new_t.task.storage = copy(storage)
new_t.task.storage[:tapedtask] = new_t
return new_t
end