R
R
raft882018-02-13 20:05:00
JavaScript
raft88, 2018-02-13 20:05:00

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

1 answer(s)
C
coderisimo, 2018-02-13
@coderisimo

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 question

Ask a Question

731 491 924 answers to any question