Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added small padding to the 1 sec API limit - occasionally hitting the…

… limit
  • Loading branch information...
commit 0e0d45adc763541226017349ae6642026a5967e7 1 parent 88748cb
Ben Hughes authored
Showing with 4 additions and 5 deletions.
  1. +4 −5 lib/posterous.js
9 lib/posterous.js
View
@@ -4,8 +4,9 @@ var api = require('./api');
var HOST = 'posterous.com';
var PATH = '/api/2/';
+var SYNC_PERIOD = 1100;
-var lastCallMade = Date.now() - 1000;
+var lastCallMade = Date.now() - SYNC_PERIOD;
// Unfortunately Posterous rate-limites API calls to 1/sec. Passing
// forceSynchronous = true will ensure that the calls comply with this limit.
@@ -86,12 +87,10 @@ Posterous.prototype.request = function(method, api, args, callback) {
Posterous.prototype.makeRequestSync = function(method, args){
var gap = Date.now() - lastCallMade;
- console.log(gap + ' ms since last execution completed');
- if(this._synchronous && gap < 1000){
- console.log('sleeping');
+ if(this._synchronous && gap < SYNC_PERIOD){
var that = this;
- setTimeout(function(){that.makeRequestSync(method, args)}, 1000);
+ setTimeout(function(){that.makeRequestSync(method, args)}, SYNC_PERIOD);
}
else{
lastCallMade = Date.now();
Please sign in to comment.
Something went wrong with that request. Please try again.