Loop without waiting for result

Hi
i need to run multiple loops without waiting for each one to end to start the next loop.

currently the loops are in one logic event. they run inside RT message listener block.

im trying to make a 3 counters on the page and i want them to start counting together when the RT event is fired.

Hello @mohammad_altoiher

I am not sure that I have understood the case.
You can create BL API service for each loop then call it async. If you need results at the end use Promise.all() like described in the following article How to wait for all Promises to resolve in JavaScript

@mohammad_altoiher

could you please share a screen of your current realization?

its UI Builder

I see what are you talking about, but unfortunately, this is not possible with Codeless at this moment. I’m going to create a ticket to add a new codeless block for running inner blocks asynchronously, something like that:

as result all the 3 requests will run in parallel, does it make sense?

As a workaround, I can recommend you to try our new Custom Code block, where you can define as input parameters references to your components and etc.
Codeless - BL - aa11aa - Backendless 2021-10-07 15-54-58

and inside the code, you can run it in parallel, what do you think?

1 Like

the ticket’s number for reference is BKNDLSS-26483

1 Like

Thank you! that will be a great add to the already awesome codeless!

i will try the custom code approach for now. thanks for the suggestion :grinning:

I’m having an issue with accessing a variable in a custom code block

i have 2 custom code blocks. Both in “On page enter” event
the first custom code block do initialization of the counter value to store it.
the second custom code is inside the RT message listener block.
i need to access the value from the first custom code block to get the value of the counter
i can access it from the console if i type the variable name. but if i try to do so from the second custom code block i got error that the variable is not defined

i know we can use “return” but its a custom library that i load and it create the counter for me. this is the library GitHub - inorganik/countUp.js: Animates a numerical value by counting to it
here is the code to create the counter

current_aya = aya; <-- this is an input to the custom code with object count from a table
ayat = new C.CountUp('main_aya_block', aya);
ayat.start()

in the RT message listener i need to do something like this to update the number
ayat.update(current_aya + rt_message);

i passed all the objects with return.
it will be much simpler if we can define global variables in custom scripts

Actually, we can
Since it is a browser environment there is a window namespace that you can use to define your global variables, see the following example:

//custom code #1
window.myVar = 123
//custom code #2
console.log(window.myVar)

i tried window before and it didn’t work
now i did with global and i got the error that its not defiend

Window works! (capital W)

oh, sorry
I mentioned window but wrote global in the example, the right way to use window in the browser and global in the Nodejs

1 Like

Window is a class
window is an instance of the class

1 Like

Hi, @mohammad_altoiher

We’ve just updated cloud servers to solve the issue you described above. We have added the new block which runs code asynchronously. The block can be found on the Advanced tab (System section). Could you please let us know if it does what you were looking for?

Regards,
Marina

1 Like