Just starting out? Need help? Post your questions and find answers here.
orangetek
 
Posts: 11
Joined: Fri Dec 08, 2017 2:32 pm

Can someone check this simple code?

by orangetek Fri Nov 01, 2019 8:45 am

Code: Select all
Repeat
  count+1
  Debug count
Until count=1000


This simple bit of code takes around 3 seconds to complete and does not display anything in the debug window until completed. Is this normal?

Thanks
User avatar
Peter
 
Posts: 691
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080

Re: Can someone check this simple code?

by Peter Fri Nov 01, 2019 2:04 pm

dev.to wrote:Javascript is a single threaded language. This means it has one call stack and one memory heap. As expected, it executes code in order and must finish executing a piece code before moving onto the next.
It's synchronous, but at times that can be harmful. For example, if a function takes awhile to execute or has to wait on something, it freezes everything up in the meanwhile.


You can use setTimeout() to avoid freezing the debug output:

Code: Select all
Procedure DebugX(DebugOutput)
  ! setTimeout(function() {
  Debug(DebugOutput)
  ! }, 0); 
EndProcedure

Repeat
  count + 1
  DebugX(count)
Until count = 1000


Greetings ... Peter
orangetek
 
Posts: 11
Joined: Fri Dec 08, 2017 2:32 pm

Re: Can someone check this simple code?

by orangetek Mon Nov 04, 2019 6:46 am

Hi Peter,

Thanks for the reply. I am still a bit confused as i thought each command was run in sequence. Can you explain where exactly the blocking is happening?
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 4 guests