# Async but ordered task queue

**URL:** <https://discourse.julialang.org/t/async-but-ordered-task-queue/126864>\
**Category:** General Usage\
**Created:** [March 12, 2025, 11:33am UTC](https://discourse.julialang.org/t/async-but-ordered-task-queue/126864 "2025-03-12T11:33:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)\
**Post date:** [March 12, 2025, 11:33am UTC](https://discourse.julialang.org/t/async-but-ordered-task-queue/126864/1 "2025-03-12T11:33:13Z")

</div>

I want to queue up some async tasks: however i’d like to push them in queues such that the order within a queue is conserved.  
Concretely, my problem are async plots into a Makie axis. My starting point is something like that:

```julia
function event_function(ax)
    @async begin
        # multiple commands manipulating axis object ax
    end
end

```

The problem arises when events are triggered in quick succession and the async tasks might overlap. What I tried next is something like this:

```julia
queue = Channel{Function} do ch
    while isopen(ch)
        task = take!(ch)
        invoke_latest(task)
    end
end

function event_function(ax)
    put!(queue, () -> begin
        # multiple commands manipulating axis object ax
    end)
end

```

but it feels a bit hacky with the `invoke_latest` and so on. Is there a “default” way of achieving this kind of behavior? Or maybe a package providing a nice abstraction for such a “task queue”?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [March 13, 2025, 5:33am UTC](https://discourse.julialang.org/t/async-but-ordered-task-queue/126864/2 "2025-03-13T05:33:54Z")

</div>

I think the ordering is a separate problem from the use of parallelization. Instead of devising some synchronization mechanism, I’d just give each “job” a number and sort them once they are finished.
