How to return values from a script that run in parallel?

Hi!

I want to have a script that will be triggered in different ways from different automations. This script, depending on conditions will be waiting for something to happen before continuing (sometimes with a timeout option): it could be waiting for a tag to be scanned, a light to turn off, a response from a user on an actionable notification on mobile, etc.

I want the automation that called the script to get the result from what happened (or not) when the script was executed, for example how did the user responded to the actionable notification or which light has been turned off, namely.

So it would help a lot if a script could simply return the value. But apparently this is not possible and we are advised to use input helpers. In principle that would work, but what if this script is called in parallel so more than one response is expected, for two completely different purposes ? One could turn off the light before responding to the actionable notification, things may happen in different orders, and the value in the input helper will be overriden. Each automation that calls the script may not be able to know whether the value in the input helper is the one it’s waiting for.

Creating many input helpers doesn’t solve the problem, as I can’t know in advance if I need one or 20. Even if I create many, that would be mess to manage.

What am I missing here to solve this?