From 28366fafe4ce8e1eb15e54e7abc322de4b37abed Mon Sep 17 00:00:00 2001 From: Shuvalov Anton Date: Wed, 20 May 2015 12:27:40 +0300 Subject: [PATCH] fix race conditions --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2f61e7c..cc3c823 100644 --- a/index.js +++ b/index.js @@ -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); };