I have some code that fetches data via a fast path, and I want to implement fallback to a slow path if the fast path isn't available. Still very new to node.js here so I'm not sure how to go about this.
Here's a simple example of what I mean:
function getThing(callback) {
var thang = getThingTheFastWay();
if (!thang) {
thang = getThingTheSlowWay();
}
if (!thang || !thang.validate()) {
return callback(new Error('invalid thang'));
}
callback(null, thang);
}
So my goal here is to do the I/O in getThingTheSlowWay()
asynchronously. Does the second half of this method need to be a callback supplied to getThingTheSlowWay()
?