-3
I recently had the following problem in a hybrid application: A command was not executed because another process was faster, and redirected the page. Not knowing how the javascript process management works (language that was not originally meant to behave like a traditional programming language) I used the setIntervel and setTimeOut functions to improvise a loading "queue", administered in milliseconds. That was the solution to that particular case, but it is far from ideal according to everything I have seen of development. I’ve never heard of programming treats in javascript, or memory management (except for the scope of var/Let variables), and to contextualize this ignorance of mine, I don’t consider myself a javascript developer, so the doubt. By coincidence, I read in a material about jquery, that the Jquery script runs when the whole page is loaded, which made me think that maybe I have an alternative to that question. If the option is developer directly to a server in nodejs, I find it unviable, because I apply javascript in "n" contexts outside of server nodejs. Note that the doubt is not exclusively about performance, more manipulating processes, where execution 1 necessarily happens before execution 2, without cluttering the code with thousands of "if"s or "dowhile".
function primeiro(){
//Esse código acontece em 500 milissegundos
}
function segundo(){
//Esse código acontece em 200 milissegundos
}
primeiro();
segundo();
" that the Jquery script runs when the whole page is loaded" this is simply the event
DOMContentLoaded
&#I suggest taking a look at the events available forwindow
anddocument
.– Ricardo Pontual
Sérgio Lima: how does the answer answer answer your question? I don’t see the relationship between the two...
– Sergio
Also did not understand the relationship of the question with the answer accepted. I understood that you want a way to ensure that
segundo()
will only be executed afterprimeiro()
finish, regardless of how long it takes - and in that case, I suggest taking a look at the Promises.performance.now()
is only measuring the time it took something to perform, IE, the functions will already have run and you did not guarantee any order...– hkotsubo
@Sergio He wanted to know what is the value of performance,he said it was right and said it solved. I’m confused...
– Maury Developer
I just found the question’s relationship with my answer strange. I even made an answer, but he said it was wrong (about performance).
– Maury Developer
I will create a different response version, to make it clear at what point your problem solves, and the traditional timers (setInterval and setTimeOut) do not solve.
– Sérgio Lima
Sérgio, it would also be interesting [Dit] the question to clarify what the problem is, so the answer starts to make more sense (because the way it is, they do not seem to have any apparent relationship).
– hkotsubo