How to wait until getting the modbus value in registered function

Hi there
This is Gopal.

Hope you are well.
Thank you for your great platform.

Currently I am working on the NodeJS project for the EEA workflow. I am using the embedded workflow.
Basically, I am using the following project as the base.

Overall, it works properly, but there is a problem regarding the registered function.

So instead of this function, I use my custom function, so in it I need to read the Modbus value of the flow meter that is connected to my device, here my device is Openwrt based gateway and it is connected to the flow meter via RS485 interface.

Here, I can not read the modbus value at all, so after reading the modbus value from the flow meter, this value should be written into the wasmMemory, but it does not work.
I know I have to make the function to wait until getting the return value for this goal, so I tried the async /await, but it failed.

Looks like the registered function does not allow the async function, but in order to get the value from the meter, my custom function should wait until the data arriving.
After getting the meter value, it should write it into the wasmMemory.

But, all that I get from the workflow live look is null value.
So how can I achieve this goal?

Thanks.
Gopal.

Yes, asynchronous functions can be challenging with WebAssembly imports, since they’re not directly supported.

There are two options:

  1. Continually read the required modbus registers in a separate setInterval and update variables that the registered function can also access. When the registered function is called, it can return the most recently read value. Might recommend pairing this with a start/stop function so the workflow can control that interval.

  2. The registered function can initiate the read and when the result is ready you can invoke the Direct Trigger with the value.

Hi @Brandon_Cannaday
Thank you for your kind update.

It makes sense, but in case that the input parameters are required from the workflow, for example, I am going to read 10 modbus register values from the register number 100 and also this parameter can be changed any time if needed, so we can not use the 1st option, this is possible when there are no input parameters. Am I right?

So I think the 2nd option is possible for this goal.
Anyway, if the async function can be used in the webassembly module, it will be great.

Thanks again.