"WAIT x seconds" control

This is my 1st post, so please be gentle with me :slight_smile:
Im trying to understand the basics of this.
Why is “wait 1 sec” in my example important for a correct result ?
Basically, i have 2 lists (list1 and list 2)
Im using list1 to get values from Firebase with a loop, then with these i populate list2
This works just fine only if after loop i insert "wait "… Why is that ? Thank you.

1 Like

I think the wait block gives Thunkable more time to get the property of the object and populate the list.

tatiang, muneer, catsarisky, and others will give you better answers since I’m not the expert on this.

1 Like

The short answer is:
If you move the label_admin as last item in the then do block of the database, you will not need the wait block.

The answer is that purple blocks in Thunkable are asynchronous blocks in nature. What does that mean? It means these blocks receive you command and work on it but will not halt your app until data is received but will allow the next command to execute (in your case, the label_admin will show nothing because the Get block is still busy.

You can switch your code to use cloud variables instead of the database blocks. cloud variables are synchronous in nature which means the block will first get the data before allowing the next block to execute.

Advice
In your code, you are looping through a list and inside the loop you use the database block. Reading from external sources is much more slower than normal block operations so as a workaround, read the whole block of data at once and save it to a variable then loop through the variable which is faster on one hand and on the other hand it would be cheaper if the access to the database is charged.

5 Likes

is the key that answers my question. My example is purely a simplifying thing of what i have, that is more complicated, so all other things dont apply.
Cant use cloud variable, as multiple users can be online at the same time, and will have acces at same “cloud” variable… and will be a mess :).
So my next question is: That "1 seconds as "wait"parameter works at this moment, giving suficient time as cloud database isnt much populated right now. But what will happen later… Is there a way to check and wait “until” datas are retrieved from cloud ?
Thank you for your time.

Later edit:
This can work ?


or will exit loop even if not the entire list is populated, giving incomplete answer then ? (as i assume)

1 Like

You can actually. Firebase data retrieved using cloud variables can easily handle unique data for each user. Each cloud variable can refer to a separate Firebase node. I’ve set up my Photo Journal app this way.

2 Likes

If you see using database blocks is unavoidable then you can do something like this

image

4 Likes