From ed70101f73b86a44057d42cc52d60a7ac48c15c6 Mon Sep 17 00:00:00 2001 From: KonStg Date: Mon, 20 Feb 2023 14:30:20 +0300 Subject: [PATCH] fixup: callback affiliation for multiple TokenRequest --- lib/token-cache.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/token-cache.js b/lib/token-cache.js index 89d263e..740eb58 100644 --- a/lib/token-cache.js +++ b/lib/token-cache.js @@ -53,19 +53,19 @@ TokenCache.prototype.authenticate = require('./auth').authenticate; */ function TokenRequest(authenticate, options) { - var self = this; this.status = 'expired'; this.pendingCallbacks = []; // execute accumulated callbacks during the 'pending' state - function fireCallbacks(err, token) { - self.pendingCallbacks.forEach(function (callback) { + TokenRequest.prototype.fireCallbacks = function (err, token) { + this.pendingCallbacks.forEach(function (callback) { callback(err, token); }); - self.pendingCallbacks = []; + this.pendingCallbacks = []; } TokenRequest.prototype.get = function (callback) { + var self = this; if (self.status == 'expired') { @@ -75,13 +75,13 @@ function TokenRequest(authenticate, options) { authenticate(options, function (err, token) { if (err) { self.status = 'expired'; - return fireCallbacks(err, null); + return self.fireCallbacks(err, null); } self.issued = Date.now(); self.duration = options.expiration || 60 * 60 * 1000; self.token = token; self.status = 'completed'; - return fireCallbacks(null, token); + return self.fireCallbacks(null, token); }); } else if (self.status == 'pending') {