@@ -42,8 +42,7 @@ function n_copies(t::Task)
4242end
4343
4444function enable_stack_copying (t:: Task )
45- state = t. state
46- if state != = :runnable && state != = :done
45+ if istaskfailed (t)
4746 error (" only runnable or finished tasks' stack can be copied." )
4847 end
4948 return ccall ((:jl_enable_stack_copying , libtask_julia), Any, (Any,), t):: Task
9493
9594function Base. copy (ctask:: CTask )
9695 task = ctask. task
97- state = task. state
98- if state != = :runnable && state != = :done
96+ if istaskfailed (task)
9997 error (" only runnable or finished tasks can be copied." )
10098 end
10199
@@ -108,9 +106,6 @@ function Base.copy(ctask::CTask)
108106 newtask. code = task. code
109107 setstate! (newtask, getstate (task))
110108 newtask. result = task. result
111- @static if VERSION < v " 1.1"
112- newtask. parent = task. parent
113- end
114109
115110 if isdefined (task, :last )
116111 newtask. last = nothing
@@ -145,13 +140,9 @@ function produce(v)
145140 end
146141
147142 # Internal check to make sure that it is possible to switch to the consumer.
148- @assert task. state in ( :runnable , :queued )
143+ @assert ! istaskdone ( task) && ! istaskfailed (task )
149144
150- @static if VERSION < v " 1.1.9999"
151- task. state === :queued && yield ()
152- else
153- task. queue != = nothing && yield ()
154- end
145+ task. queue != = nothing && yield ()
155146
156147 if empty
157148 # Switch to the consumer.
@@ -220,7 +211,7 @@ function consume(ctask::CTask, values...)
220211 end
221212
222213 # If the task failed, throw an exception.
223- _istaskfailed (producer) && throw (CTaskException (producer))
214+ istaskfailed (producer) && throw (CTaskException (producer))
224215
225216 # If the task is done return the result.
226217 istaskdone (producer) && return producer. result
@@ -229,14 +220,6 @@ function consume(ctask::CTask, values...)
229220 wait ()
230221end
231222
232- function _istaskfailed (task:: Task )
233- @static if VERSION < v " 1.3"
234- return task. state === :failed
235- else
236- return Base. istaskfailed (task)
237- end
238- end
239-
240223function getstate (task:: Task )
241224 @static if VERSION < v " 1.6.0-DEV.618"
242225 return task. state
0 commit comments