Permalink
Browse files

Initial stab at subscription callbacks to detect when a subscription …

…is accepted.
  • Loading branch information...
1 parent 9ffe44d commit 945fe354c94bdd3a40740ab4b316eaf3b19a9042 @jcoglan jcoglan committed Nov 5, 2010
Showing with 13 additions and 5 deletions.
  1. +3 −1 javascript/protocol/client.js
  2. +2 −0 javascript/protocol/subscription.js
  3. +8 −4 test/scenario.js
@@ -166,6 +166,7 @@ Faye.Client = Faye.Class({
}, this);
this._validateChannel(channels);
+ var subscription = new Faye.Subscription(this, channels, callback, scope);
this.connect(function() {
this.info('Client ? attempting to subscribe to ?', this._clientId, channels);
@@ -181,11 +182,12 @@ Faye.Client = Faye.Class({
var channels = [].concat(response.subscription);
this.info('Subscription acknowledged for ? to ?', this._clientId, channels);
this._channels.subscribe(channels, callback, scope);
+ subscription.setDeferredStatus('succeeded');
}, this);
}, this);
- return new Faye.Subscription(this, channels, callback, scope);
+ return subscription;
},
// Request Response
@@ -18,3 +18,5 @@ Faye.Subscription = Faye.Class({
}
});
+Faye.extend(Faye.Subscription.prototype, Faye.Deferrable);
+
View
@@ -76,11 +76,15 @@ AsyncScenario = Faye.Class({
this._inbox[name] = {};
this._pool += 1;
+ var completed = 0;
+ if (channels.length === 0) return Continue();
+
Faye.each(channels, function(channel) {
- this.subscribe(name, channel);
+ this.subscribe(name, channel, function() {
+ completed += 1;
+ if (completed === channels.length) Continue();
+ });
}, this);
-
- setTimeout(Continue, 500 * channels.length);
},
subscribe: function(name, channel, Continue) {
@@ -92,7 +96,7 @@ AsyncScenario = Faye.Class({
box[channel].push(message);
}, this);
- setTimeout(Continue, 500);
+ this._lastSub.callback(Continue);
},
cancelLastSubscription: function(Continue) {

0 comments on commit 945fe35

Please sign in to comment.