Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

… limit
  • Loading branch information...
commit 0e0d45adc763541226017349ae6642026a5967e7 1 parent 88748cb
Ben Hughes authored February 21, 2012

Showing 1 changed file with 4 additions and 5 deletions. Show diff stats Hide diff stats

  1. 9  lib/posterous.js
9  lib/posterous.js
@@ -4,8 +4,9 @@ var api = require('./api');
4 4
 
5 5
 var HOST = 'posterous.com';
6 6
 var PATH = '/api/2/';
  7
+var SYNC_PERIOD = 1100;
7 8
 
8  
-var lastCallMade = Date.now() - 1000;
  9
+var lastCallMade = Date.now() - SYNC_PERIOD;
9 10
 
10 11
 // Unfortunately Posterous rate-limites API calls to 1/sec. Passing 
11 12
 // forceSynchronous = true will ensure that the calls comply with this limit.
@@ -86,12 +87,10 @@ Posterous.prototype.request = function(method, api, args, callback) {
86 87
 
87 88
 Posterous.prototype.makeRequestSync = function(method, args){
88 89
   var gap = Date.now() - lastCallMade;
89  
-  console.log(gap + ' ms since last execution completed');
90 90
 
91  
-  if(this._synchronous && gap < 1000){
92  
-      console.log('sleeping');
  91
+  if(this._synchronous && gap < SYNC_PERIOD){
93 92
       var that = this;
94  
-      setTimeout(function(){that.makeRequestSync(method, args)}, 1000);
  93
+      setTimeout(function(){that.makeRequestSync(method, args)}, SYNC_PERIOD);
95 94
   }
96 95
   else{
97 96
     lastCallMade = Date.now();

0 notes on commit 0e0d45a

Please sign in to comment.
Something went wrong with that request. Please try again.