What 'Code' is executed at what time?

Hey Guys,
I have some trouble understanding how the ‘timeline’ or execution of blocks works.
My precise problem is that I use one Button which has 2 functions inside.

  1. function: upload some images to cloudinary and get their urls
  2. function: create a new object with some info and these image urls and upload them into a database (webapi)

Now, I noticed that sometimes the urls from function 1 make it into the database in function 2 and sometimes not. I added some random points in the code where it waits for a second or two. That increased the chance of landing in the database but it does not always happen.

So in general I thought one block is executed after the one before. So function 1 should finish before function 2 right? Is that that always the case? If no, when not and where can I learn about it?

A second question regarding this: if I WANT things to happen simultaniously, how do I do this? eg I want a sound recording of 5 seconds. (the recording block lets my do this). But I also want a timer to run for 5 seconds at the same time to show the user how much time he has left. So far my timer shows the 5 seconds and THEN the recording starts :sweat_smile:

A bit lost on the topic. Any source or info would help :wink:

cheers!

1 Like

Check out this discussion on asynchronous processing in Thunkable.

3 Likes

ah man, that is genius! Exactly what I need to know. Thanks alot!
Do you also have any idea for the second question: How to execute some blocks at the same time?

1 Like

I believe @tatiang did something with sound and timers.

Did I? I probably did! I have so many demos lying around.

I’m not recalling that but executing blocks at the same time… you’d just have two event blocks.

So instead of this:

On button click
     Play sound
     Start timer

You would have this:

On button click
     Play sound

On button click 
     Start timer
3 Likes

I was thing of this post

3 Likes

ah the problem is this:
I record a sound and the recorder block has a function “record for x seconds”. So you start it, it records for X seconds and stops. No matter which way you turn it: either the timer or the recording rund for X seconds before the other one start.

I have an idea how to solve this, as there is a different recorder block which just starts the recording. I can then run the timer and then stop the recording.

I was just curious if there was a general way how to start multiple tasks at the same time :wink:

thanks a lot for your time and help!!

1 Like

Don’t use the built-in timer. Just use the “seconds since 1970” block in the Device drawer. You can set a variable to that block just before you start recording. Then, after the recording is done, compare the time by setting a different variable to seconds since 1970 minus the first variable. That will give you the amount of time that has elapsed.

2 Likes