Skip to content

Commit

Permalink
Merge pull request #20 from mapbox/no-retry-dep
Browse files Browse the repository at this point in the history
Remove retry dependency.
  • Loading branch information
yhahn committed Jun 9, 2014
2 parents 52ac72a + 27d3a1d commit 111c06b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
34 changes: 16 additions & 18 deletions lib/tilejson.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var path = require('path');
var fs = require('fs');
var url = require('url');
var get = require('get');
var retry = require('retry');
var tiletype = require('tiletype');
var EventEmitter = require('events').EventEmitter;
var Agent = require('agentkeepalive');
Expand Down Expand Up @@ -194,24 +193,23 @@ TileJSON.prototype.getGrid = function(z, x, y, callback) {
// with additional caching, etc., if desired.
TileJSON.prototype.get = function(url, callback) {
var tilejson = this;
var operation = retry.operation({
retries: 1
});

operation.attempt(function(current) {
new get({
uri: url,
timeout: tilejson.timeout,
headers: {Connection:'Keep-Alive'},
agent: url.indexOf('https:') === 0 ? httpsagent : agent
}).asBuffer(function(err, result, headers) {
// Retry if status is missing or in the 5XX range.
if (err && (!err.status || err.status >= 500)) {
if (operation.retry(err)) return;
}
var opts = {
retry: true,
uri: url,
timeout: tilejson.timeout,
headers: {Connection:'Keep-Alive'},
agent: url.indexOf('https:') === 0 ? httpsagent : agent
};
new get(opts).asBuffer(done);
function done(err, result, headers) {
// Retry if status is missing or in the 5XX range.
if (err && (!err.status || err.status >= 500) && opts.retry) {
opts.retry = false;
new get(opts).asBuffer(done);
} else {
callback(err, result, headers);
});
});
}
}
};

// Helper for locking multiple requests for the same IO operations to a
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"dependencies": {
"get": "1.3.x",
"agentkeepalive": "0.1.x",
"tiletype": "0.0.x",
"retry": "0.6.0"
"tiletype": "0.0.x"
},
"devDependencies": {
"mocha": "*"
Expand Down

0 comments on commit 111c06b

Please sign in to comment.