Below outlines a promise that has two simple steps display on the console something, then display something else after the first step is completed.
I am trying to understand how to resolve the promise, and allow the 2nd step to complete.
var lookup_documents = new Promise(
function(resolve, reject) {
console.log("1st");
//resolve(); - How do I do this outside of this function?
}
);
lookup_documents.then(
function() {
console.log("2nd");
}
);
Normally you use
new Promise()
when you want to wrap some asynchronous function into a promise, such as:There are other Promise implementations, such as
q
, where you can create a "deferred" object that returns a promise... Something similar would be:For the specific thing you want... All I can think of is declare a variable outside of the promise function scope and asign it, something like:
But that doesn't look too good and can lead to errors... Try to wrap everything in your Promise function.