Monday, 5 June 2017
node.js - Resolving a setTimeout inside API endpoint
Answer
I need to add a delay to an API call so I'm using setTimeout. After 2 seconds on success, I need to return res.status(200).json(response).
exports.someEndpoint = function(req, res) {
return request.post({
url: //etc
})
.then(function(response) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
// is this right?
resolve(
res.status(200).json(response);
);
}, 2000);
});
});
};
My question is: do I need to call resolve inside the setTimeout? Or can I just completely omit it?
Subscribe to:
Post Comments (Atom)
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
Iv'e read a lot of posts both in stackoverflow and other websites talking about web security. Such as salting encrypting etc. ...
-
System.out.print("Name : "); String name = in.nextLine(); System.out.print("Age : "); int age = ...
-
In K-PAX , there are two possible explanations: Prot is crazy. He is truly an alien. There are facts that indicate 1, but also 2. Examples: ...
No comments:
Post a Comment