Force One Message at a Time?

I'm looking for a way to only allow a single message to be processed at a time through a block of my flow. I'd like to use a queue to queue the rest. Was going to use q-gate, but it's missing one feature. If the queue runs empty I'd like to automatically open the queue. q-gate doesn't seem to have a way to do that. Basically when I get to the end of a run either de-queue the next item or if the queue is empty, just go to the open state. e.g. automatically de-queue if it gets another message while i'm not processing. Anyone know a simple way?

What I think you need is the delay node.

Put that in and then open it (edit it)

Then select rate limit

Screenshot from 2022-05-20 07-01-10

Hello, and welcome to node-red!

Take a look at the brilliantly simple node-red-contrib-semaphore

It's just a pair of nodes that lets your flow take a "ticket" from a configurable pool of tickets (in your case it's just the 1), and some time later your flow can "leave" that ticket, which immediately makes it available for the next msg in line to take it. Every msg that reaches the semaphore-take node after the pool is empty gets queued up until a semaphore becomes available by another msg reaching the semaphore-leave node.

The only thing to watch for is that you never want to take a semaphore without later returning it -- or else your queued up msgs will never be released. Best practice is to put a watch node on any nodes between the semaphores, to catch exceptions (e.g. an http-request that fails).

I can probably dig up an example of a flow that limits how many msgs can be "in-flight", if you get stuck trying to set it up -- but it's pretty simple to use. Good luck!