image subscriptions was not always properly unsubscribing; fixed

This commit is contained in:
Emi Matchu 2012-07-27 23:34:19 -04:00
parent 42827362b6
commit 5f48dd0f0e

View file

@ -1126,7 +1126,8 @@ function Wardrobe() {
log("Outfit image still enqueued; will try again soon", outfit);
setTimeout(function () { checkSubscription(outfit) }, DELAY);
} else {
controller.unsubscribe(outfit);
// Unsubscribe everyone from this outfit and fire ready events
delete outfitSubscriptionTotals[outfit.id];
controller.events.trigger('imageReady', outfit);
}
} else {
@ -1137,18 +1138,19 @@ function Wardrobe() {
}
this.subscribe = function (outfit) {
if(outfit.image_enqueued) {
if(outfit.id in outfitSubscriptionTotals) {
// The subscription is already running. Just mark that one more
// consumer is interested in it, and they'll all get a response soon.
outfitSubscriptionTotals[outfit.id] += 1;
} else {
// This is a new subscription!
// This is a new subscription! Let's start checking it.
outfitSubscriptionTotals[outfit.id] = 1;
if(outfit.image_enqueued) {
// If the image is enqueued, trigger that event and start checking.
controller.events.trigger('imageEnqueued', outfit);
checkSubscription(outfit);
}
// Regardless, trigger the enqueued event for the new consumer's sake.
controller.events.trigger('imageEnqueued', outfit);
} else {
// Otherwise, never bother checking: skip straight to the ready phase.
// Give it an instant timeout so that we're sure the consumer is ready
@ -1162,7 +1164,6 @@ function Wardrobe() {
return outfit;
}
}
this.unsubscribe = function (outfit) {
if(outfit && outfit.id in outfitSubscriptionTotals) {