Should be fine to have them just return the results of their work. If they need to pass an error to the caller use the node convention of having synchronous functions throw, e.g.
function mySyncFunc() {
throw new Error("Gah this is a sync error");
return "Great data";
}
You'll see this pattern around any node core sync calls, e.g.
// Sync version
try {
var data = fs.readFileSync('./filedoesntexist');
} catch(err) {
if (err && err.code === 'ENOENT') console.log('No file, ignore');
}
// Async version
fs.readFile('./filedoesntexist', function(err) {
if (err && err.code === 'ENOENT') console.log('No file, ignore');
});
These three functions currently take callbacks but are actually synchronous:
https://github.com/mapbox/abaculus/blob/master/index.js#L46-L153
Should be fine to have them just
return
the results of their work. If they need to pass an error to the caller use the node convention of having synchronous functions throw, e.g.You'll see this pattern around any node core sync calls, e.g.