Skip to content

Commit

Permalink
Extract TapedTask try-catch method (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer authored Feb 18, 2022
1 parent 8aaea77 commit c81dab8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/tapedtask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ struct TapedTask
end
end

function TapedTask(tf::TapedFunction, args...)
produce_ch = Channel()
consume_ch = Channel{Int}()
task = @task try
function wrap_task(tf, produce_ch, consume_ch, args...)
try
producer = () -> begin
ttask = current_task().storage[:tapedtask]
if length(ttask.produced_val) > 0
Expand All @@ -45,6 +43,12 @@ function TapedTask(tf::TapedFunction, args...)
close(produce_ch)
close(consume_ch)
end
end

function TapedTask(tf::TapedFunction, args...)
produce_ch = Channel()
consume_ch = Channel{Int}()
task = @task wrap_task(tf, produce_ch, consume_ch, args...)
t = TapedTask(task, tf, produce_ch, consume_ch)
task.storage === nothing && (task.storage = IdDict())
task.storage[:tapedtask] = t
Expand Down

0 comments on commit c81dab8

Please sign in to comment.