# PLATFORM.taskqueue does not run concurrent tasks

**URL:** <https://discourse.aurelia.io/t/platform-taskqueue-does-not-run-concurrent-tasks/5379>\
**Category:** Help Requests\
**Created:** [March 13, 2024, 12:00pm UTC](https://discourse.aurelia.io/t/platform-taskqueue-does-not-run-concurrent-tasks/5379 "2024-03-13T12:00:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarp](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@sarp](https://discourse.aurelia.io/u/sarp)\
**Post date:** [March 13, 2024, 12:00pm UTC](https://discourse.aurelia.io/t/platform-taskqueue-does-not-run-concurrent-tasks/5379/1 "2024-03-13T12:00:18Z")

</div>

Hey people!

I am using the PLATFORM.taskQueue in several places throughout my app, and globally at the topbar to show time down to seconds. Every now and then, the seconds would stop counting and I never really realized a pattern until recently as to why.

It seems when I queue a task with a delay, it halts the execution of other queued tasks. When I think about it now, it makes sense, if there is one single task queue, the delay of the next-in-line task should stall the others, however the way PLATFORM.taskQueue is described in the docs as a direct alternative to setTimeout or setInterval is misleading in this case, since there is a very strict difference between the two approaches: being concurrent vs. being consecutive.

Is there something that I am missing in the docs, or not seeing in the API? If not, it would make sense to clarify this difference in the docs or maybe allow concurrency somehow. Because as is, contrary to what the docs would make the reader believe, taskQueue is not really a substitute of the latter two.

It seems there is a GitHub issue pointing to this behaviour: [Platform taskQueue multiple instances all use the same delay value · Issue #1542 · aurelia/aurelia · GitHub](https://github.com/aurelia/aurelia/issues/1542)

which is also referenced from this topic: [Multiple PLATFORM queueTask timing problem](https://discourse.aurelia.io/t/multiple-platform-queuetask-timing-problem/4898)

I created a small repro of the issue: The two counts should meet at multiples of 10, but they don’t:

> **[Aurelia 2 Typescript (forked) - StackBlitz](https://stackblitz.com/edit/aurelia-2-typescript-tzhepx)**
>
> A blank Aurelia 2 / TypeScript starter.

---

<div class="post-metadata">

**Author:** ![fkleuver](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/fkleuver/32/994_2.png) [@fkleuver](https://discourse.aurelia.io/u/fkleuver)\
**Post date:** [July 12, 2024, 11:46am UTC](https://discourse.aurelia.io/t/platform-taskqueue-does-not-run-concurrent-tasks/5379/2 "2024-07-12T11:46:51Z")

</div>

FYI, this PR fixes it so it should be soon released with the new dev version:

> <https://github.com/aurelia/aurelia/pull/2007>
>
> \<!---
> Thanks for filing a pull request 😄 ! Before you submit, please read the f…ollowing:
> 
> Search open/closed issues before submitting since someone might have pushed the same thing before!
> \--\>
> 
> \# Pull Request
> 
> \## 📖 Description
> 
> Fixes an issue in the task queue when using multiple persistent delayed tasks with different timings.
> 
> 
> \<!---
> Provide some background and a description of your work.
> \--\>
> 
> \### 🎫 Issues
> 
> \- close https://github.com/aurelia/aurelia/issues/1542
> \- resolve https://discourse.aurelia.io/t/platform-taskqueue-does-not-run-concurrent-tasks/5379
> \- resolve https://discord.com/channels/448698263508615178/448699089513611266
> \<!---
> \* List and link relevant issues here.
> \--\>
> 
> \## 👩‍💻 Reviewer Notes
> 
> There was a small oversight in the queue processing loop where it assumed the smallest delay task to be in the front of the queue. It now checks all tasks in the delayed task list.
> \<!---
> Provide some notes for reviewers to help them provide targeted feedback.
> \--\>
> 
> \## 📑 Test Plan
> 
> A single test covers this bug properly. Without the fix, it fails with \`counter10\` and \`counter20\` being equal. Now it's doubled (though I added some leeway in there to account for flakiness)
> \<!---
> Please provide a summary of the tests affected by this work and any unique strategies employed in testing the features/fixes.
> \--\>
> 
> \## ⏭ Next Steps
> 
> \<!---
> If there is relevant follow-up work to this PR, please list any existing issues or provide brief descriptions of what you would like to do next.
> \--\>
> 
> \<!--
> Love Aurelia? Please consider supporting our collective:
> 👉 https://opencollective.com/aurelia
> \--\>

Thank you for the clean repro, it helped!

---

<div class="post-metadata">

**Author:** ![sarp](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@sarp](https://discourse.aurelia.io/u/sarp)\
**Post date:** [July 12, 2024, 12:18pm UTC](https://discourse.aurelia.io/t/platform-taskqueue-does-not-run-concurrent-tasks/5379/3 "2024-07-12T12:18:00Z")

</div>

You are most welcome @fkleuver and thank you too. Looking forward to test it in the next release 👍
