What’s the best way to construct a
Task which has already completed? My current best shot is
t = @async nothing wait(t)
but this feels both clumsy and inefficient.
The use case is that I would like to have a background task with the following behaviour.
- Start when work comes in and there isn’t already a background task running.
- Keep running while there’s work, then shut down once there’s no more work left.
In somewhat pseudo-code-ish Julia, this can be achieved as follows.
# Initialize work_queue =  t = task_which_is_already_done() # When work comes in push!(work_queue, work) if istaskdone(t) t = @async begin while !isempty(work_queue) process(pop!(work_queue)) end end end