'Why use return for methods that do not need a return value?
When I read the source code, I found that the author will use return where there is no need to use return.
exports.getPort = function (options, callback) {
// code...
return _async.eachSeries(exports._defaultHosts, function(host, next) {
// code ...
return next();
}
}
What is the purpose or need of this usage?
Solution 1:[1]
next is likely a promise. Maybe in your code it is not used (no then / catch), but there might (and should) be some.
In case the promise was not returned then there is no way to catch errors or make sequentials asynchronous calls.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ji aSH |