Hi, I am wondering if there is a better way of implementing a function with asynchronous block (in particular, Web API) with a return value that depended on the results of the asynchronous block.
I need to call the above function multiple times, and used delay to guarantee correct values are returned, but this way slowed down the my app significantly. Just saw the conditional-return block.
I was wondering if anyone know how to use this, potentially can improve efficiency of the function?
Yes. I have used the recursive function to make my other wepAPI calls for data. But for this function, the conversion from unixtime to readable date/time function was needed everywhere in my app. They is no there is no way I can make it recursive. Hence trying to find a way to work around.
If you need a function on different screens, then you need to make this function global. You can see an example of a global function on the scrTitle and scrGlobalFunction screens in the project
Thanks actech. Fantastic demo app. Yes that’s what I need, making the functions global so I can consistently use it across my screens. And I agree that delay blocks with asynchronous functions gave unforeseeable random errors, because I will never know how long it takes for a web call to return the results. I made a work around as shown below:
This block is used for immediate exit from the function if the condition in it is true. For example, your function should find and return the found value. You can make a condition in the loop and when it is triggered, abort the loop and return the result, or you can immediately abort the function when the condition is met and return the specified value.