Answer the question
In order to leave comments, you need to log in
How to make synchronous functionality on asynchronous node + vanilla JS?
Good afternoon.
I am writing a small program on an electron, at startup the program must do several operations with the server.
For all known reasons ("this will be faster", "no time to look at FW", etc.) I decided to write everything in pure JS.
So, I am friends with asynchrony and the concept of this technology. but I want to solve the starting functionality synchronously, i.e.:
this is how it works now:
app.on('ready', register)
function register() {
doThis("abc", myCallback)
}
function myCallback(request, error...) {
if(request.message == "foobar") {
doThat("cba", otherCallback);
}
}
function otherCallback(request, error...) {
doSomething(request.foo);
}
app.on('ready', register)
function register() {
var request = doThis("abc");
if(request.message == "foobar") {
var someVar = doThat("cba");
console.log(someVar);
}
}
Answer the question
In order to leave comments, you need to log in
Use callbacks and promises .
Here , for example, about fs. You can immediately flip through the examples.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question