@@ -8,6 +8,12 @@ struct TapedTask
8
8
counter:: Ref{Int}
9
9
produce_ch:: Channel{Any}
10
10
consume_ch:: Channel{Int}
11
+ produced_val:: Vector{Any}
12
+
13
+ function TapedTask (
14
+ t:: Task , tf:: TapedFunction , counter, pch:: Channel{Any} , cch:: Channel{Int} )
15
+ new (t, tf, counter, pch, cch, Any[])
16
+ end
11
17
end
12
18
13
19
function TapedTask (tf:: TapedFunction , args... )
@@ -55,6 +61,13 @@ function step_in(tf::TapedFunction, counter::Ref{Int}, args)
55
61
tf. tape[counter[]]()
56
62
counter[] += 1
57
63
end
64
+ # produce and wait after an instruction is done
65
+ ttask = t. owner. owner
66
+ if length (ttask. produced_val) > 0
67
+ val = pop! (ttask. produced_val)
68
+ put! (ttask. produce_ch, val)
69
+ take! (ttask. consume_ch) # wait for next consumer
70
+ end
58
71
end
59
72
60
73
# A way (the old way) to impl `produce`, which does NOT
@@ -68,7 +81,12 @@ function internal_produce(instr::Instruction, val)
68
81
end
69
82
70
83
function produce (val)
71
- error (" Libtask.produce can only be directly called in a task!" )
84
+ # # error("Libtask.produce can only be directly called in a task!")
85
+ # put!(ttask.produce_ch, val)
86
+ # take!(ttask.consume_ch) # wait for next consumer
87
+ length (ttask. produced_val) > 1 &&
88
+ error (" There is a produced value which is not consumed." )
89
+ push! (ttask. produced_val, val)
72
90
end
73
91
74
92
function (instr:: Instruction{typeof(produce)} )()
0 commit comments