mapbox / abaculus

Library for creating static maps from tiles based on center or corner lng,lat coordinates. Uses node-blend.
ISC License
127 stars 38 forks source link

Util functions that are faux async #1

Closed yhahn closed 10 years ago

yhahn commented 10 years ago

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.

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');
});