Are promises blocking? #1679
Replies: 3 comments
-
Posted at 2023-11-22 by user156811 It actually might be the fact that my task is running a little longer then i first thought. So i'm guessing until my main task is finished or is halted by a promises. A set timeout won't trigger? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-11-22 by user156811 Also sorry for my bad terminology. I don't actually know how to describe of Environment. Its like a light multitasking environment. Javascript as a "operating system". |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-11-22 by @gfwilliams Your terminology sounds fine to me! A promise chain itself is not blocking but in JavaScript the execution of function code is (unless you declare it 'async' which Espruino doesn't support - but all that does it effectively split the function into a bunch of smaller sync functions joined with promises). So Espruino can only run one bit of code at a time (it's not pre-emptive), but by splitting the code up and calling the next bit of code from a promise/callback it can then interleave those smaller bits of code and make it seem multi-tasking. So in your case as you noted I think maybe one part of the promise is just taking a long time to finish? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-11-21 by user156811
I have a simple blinking light in the background on my NRF52840 board. It blinks every like 1 second. But when i'm waiting for one of my promises to resolve the blinking light seems to be not working.
So do promises block the thread?
Beta Was this translation helpful? Give feedback.
All reactions