r/tasker • • Oct 26 '26

Task collision and single threading

Hi,

I have a profile that intercepts notifications from an app and fires off a task to process the notification contents.

The app in question can issue several notifications at the same time. How can I ensure that the triggered task is single threaded, with only one task instance running at a time while at the same time getting the correct information from the notification that it is processing. 

There is an option in task settings to 'Run Both Together' but I don't want the task activity to be interlaced and anyway there could be more than 2 instances at play here. I'm looking at setting up a lock/unlock gate mechanism at the start and end of the task, but not sure of the exact best way to approach this (or if there is another way to guarantee task single threading).

Appreciate any advice.

TIA.

2 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/Exciting-Compote5680 Oct 27 '26

Aren't you just moving the bottleneck from one task to another? Tasks are already queued, this just adds more overhead. 

2

u/DylanXu054728 Oct 27 '26

Fair question, but they aren't queued as whole tasks. The Scheduling section on the Tasks page of the userguide says instances with the same priority take turns executing one action each, starting with the most recently added one. So with Run Both Together and three notifications arriving at once, you get three copies interleaved action by action, with the newest one going first. That's the interlacing OP said they wanted to avoid.

With the array, each notification is processed start to finish before the next one, in the order they arrived. The extra cost is one push, one pop and one Goto per notification, which is nothing next to the actual processing.

If the processing is just a couple of quick actions with no Wait or HTTP Request in it, the interleaving probably won't matter and plain Run Both Together is fine.

1

u/dougwzz99 Oct 27 '26 edited Oct 28 '26

I'm already using the approach that you outlined with the notification profile task simply doing a PUSH with the required information into a global array. A seperate profile then triggers when it detects an entry to the array, and the associated task then does the POP and processes the array element, looping until the array is empty.

My concern was that even the simple task doing the PUSH action would have issues if it was triggered multiple times in quick succession, and I also wasn't sure about any interlacing that might result from Run Both Together.

This discussion and some testing I've done has convinced me that I was overthinking this :-) Any interlacing that may or may not occur is irrelevant with the separation of processing provided by the PUSH/POP approach.

Thanks to all for the assistance.

1

u/Exciting-Compote5680 Oct 27 '26

I thought tasks launched by the same profile were always executed in order, with the next run only starting when the previous has completed (unless 'Enforce Task Order' is disabled). But the queuing task might help avoid hitting the queue limit by acting as a buffer. Might need to call the processing task with lower priority though.