Skip to content

Commit

Permalink
fix race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
A committed May 20, 2015
1 parent edce867 commit 28366fa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ function mock(superagent) {
// Patch Request.end()
var oldEnd = superagent.Request.prototype.end;
superagent.Request.prototype.end = function(cb) {
var self = this;
var current = state.current;
setTimeout(function() {
state.current
? cb(null, state.current())
current
? cb(null, current())
: oldEnd.call(this, cb);
}, 0);
};
Expand Down

0 comments on commit 28366fa

Please sign in to comment.