Skip to content

Commit 2a7ff14

Browse files
committed
fix #120
1 parent 90b3e75 commit 2a7ff14

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/kuzzleRoom.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ function KuzzleRoom(kuzzleDataCollection, options) {
4545
value: null,
4646
writable: true
4747
},
48+
onDoneCB: {
49+
value: null,
50+
writable: true
51+
},
4852
queue: {
4953
value: [],
5054
writable: true
@@ -166,13 +170,17 @@ KuzzleRoom.prototype.renew = function (filters, notificationCB, cb) {
166170
filters = null;
167171
}
168172

173+
if (!cb) {
174+
cb = self.onDoneCB;
175+
}
176+
169177
self.kuzzle.callbackRequired('KuzzleRoom.renew', notificationCB);
170178

171179
/*
172180
Skip subscription renewal if another one was performed a moment before
173181
*/
174182
if (self.lastRenewal && (now - self.lastRenewal) <= self.renewalDelay) {
175-
return;
183+
return cb && cb(new Error('Subscription already renewed less than ' + self.renewalDelay + 'ms ago'));
176184
}
177185

178186
if (filters) {
@@ -185,6 +193,7 @@ KuzzleRoom.prototype.renew = function (filters, notificationCB, cb) {
185193
*/
186194
if (self.kuzzle.state !== 'connected') {
187195
self.callback = notificationCB;
196+
self.onDoneCB = cb;
188197
self.kuzzle.subscriptions.pending[self.id] = self;
189198
return;
190199
}
@@ -198,6 +207,7 @@ KuzzleRoom.prototype.renew = function (filters, notificationCB, cb) {
198207
self.roomId = null;
199208
self.subscribing = true;
200209
self.callback = notificationCB;
210+
self.onDoneCB = cb;
201211
self.kuzzle.subscriptions.pending[self.id] = self;
202212

203213
subscribeQuery.body = self.filters;

0 commit comments

Comments
 (0)