Answer the question
In order to leave comments, you need to log in
How to terminate async waterfall?
Good afternoon. I am using the async module in node.js.
The question arose how to properly complete the execution of the async waterfall.
The logic is as follows: request a cache, if there is a cache - give an answer immediately, if there is no cache - make a request to api
So if there is a cache, you want to complete the waterfall right away. It is possible to pass the cache object as the first parameter in the callback as an error, but this is somehow ugly and may not be obvious to others. Are there any other options?
Answer the question
In order to leave comments, you need to log in
Instead of it is easier to make on promises?
Pseudocode:
cache.get(key).then((data) => {
if (data) return data;
return api.something;
});
Is a waterfall really needed here? Getting a cache is a blocking operation? If so, then you can wrap it in a regular promise. According to your description, it seems to me that it is possible to do without a
waterfall as it is needed to sequentially run functions with blocking operations and the ability to pass arguments from one to the next ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question