Answer the question
In order to leave comments, you need to log in
How to use promises inside a function?
Help me to understand!
The original code was written like this:
function foo(arg){
............
let name = newFoo();
.............
return result;
}
function newFoo() {
return new Promise(............resolve(result)).then((result) => {......... ........return obj; })
}
in the newFoo function, an object was formed from the data, which was then used in the main foo function. Now there is a need to write the data received asynchronously into the object. How to implement all this on a promise? How to write this object to the name variable???
Answer the question
In order to leave comments, you need to log in
In a promise, put the return result in resolve(result_here)
then:
let name = newFoo();
name.then(function(result_here)){
// use the result here
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question