diff --git a/lib/tilejson.js b/lib/tilejson.js index e198b3b..a0f2e9d 100644 --- a/lib/tilejson.js +++ b/lib/tilejson.js @@ -30,8 +30,7 @@ function TileJSON(uri, callback) { else if (typeof uri.query === 'string') uri.query = qs.parse(uri.query); if (!uri.pathname && !uri.data) { - callback(new Error('Invalid URI ' + url.format(uri))); - return; + return setImmediate(callback, new Error('Invalid URI ' + url.format(uri))); } if (uri.hostname === '.' || uri.hostname == '..') { @@ -94,7 +93,7 @@ function TileJSON(uri, callback) { } TileJSON.prototype.close = function(callback) { - if (callback) callback(null); + if (callback) setImmediate(callback); }; TileJSON.registerProtocols = function(tilelive) { @@ -127,14 +126,14 @@ TileJSON.findID = function(filepath, id, callback) { }; TileJSON.prototype.getInfo = function(callback) { - if (!this.data) callback(new Error('Tilesource not loaded')); - else callback(null, this.data); + if (!this.data) setImmediate(callback, new Error('Tilesource not loaded')); + else setImmediate(callback, null, this.data); }; // z, x, y are XYZ coordinates. TileJSON.prototype.getTile = function(z, x, y, callback) { - if (!this.data) return callback(new Error('Tilesource not loaded')); - if (!this.data.tiles) return callback(new Error('Tile does not exist')); + if (!this.data) return setImmediate(callback, new Error('Tilesource not loaded')); + if (!this.data.tiles) return setImmediate(callback, new Error('Tile does not exist')); var url = this._prepareURL(this.data.tiles[0], z, x, y); this.get(url, function(err, data, headers) {