11 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
in a dirty way you can use
while (true)
with date diffing to stop the loop
but the question is: why do you need synchronous waiting?No I mean there was console.log('first') after that setTimeout(console.log('hi') , 0)
Question is how to make settimeout console to display first followed by first console?
you would like to await it
or
.then()
the promise instead of await
ing it
!mdn await!mdn Promise.prototype.then
By the way, your question indicates that you are new to event loop (or asynchrony at all) inside JS. So i'd recommend you to get familiar with it:
https://www.youtube.com/watch?v=8aGhZQkoFbQ
https://javascript.info/async
JSConf
YouTube
What the heck is the event loop anyway? | Philip Roberts | JSConf EU
JavaScript programmers like to use words like, “event-loop”, “non-blocking”, “callback”, “asynchronous”, “single-threaded” and “concurrency”.
We say things like “don’t block the event loop”, “make sure your code runs at 60 frames-per-second”, “well of course, it won’t work, that function is an asynchronous callback!”
If you’re anything like me...
When we use await
So the output is
console.log('hi')
console.log ('first')
Thanks u @ScriptyChris
though remember that
await
may only be used inside async
function or at the top level of module file
(or in console)Ok thank u very much
This thread hasn’t had any activity in 12 hours, so it’s now locked.
Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/939193653807693844