forked from OpenNeo/impress
image subscriptions was not always properly unsubscribing; fixed
This commit is contained in:
parent
42827362b6
commit
5f48dd0f0e
1 changed files with 23 additions and 22 deletions
|
@ -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,31 +1138,31 @@ function Wardrobe() {
|
|||
}
|
||||
|
||||
this.subscribe = function (outfit) {
|
||||
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!
|
||||
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);
|
||||
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 {
|
||||
// Otherwise, never bother checking: skip straight to the ready phase.
|
||||
// Give it an instant timeout so that we're sure the consumer is ready
|
||||
// for the event. (It can be tricky when the consumer assigns this
|
||||
// return value somewhere to know if it cares about the event, so the
|
||||
// event can't fire before the return.)
|
||||
setTimeout(function () {
|
||||
controller.events.trigger('imageReady', outfit)
|
||||
}, 0);
|
||||
// This is a new subscription! Let's start checking it.
|
||||
outfitSubscriptionTotals[outfit.id] = 1;
|
||||
checkSubscription(outfit);
|
||||
}
|
||||
|
||||
return 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
|
||||
// for the event. (It can be tricky when the consumer assigns this
|
||||
// return value somewhere to know if it cares about the event, so the
|
||||
// event can't fire before the return.)
|
||||
setTimeout(function () {
|
||||
controller.events.trigger('imageReady', outfit)
|
||||
}, 0);
|
||||
}
|
||||
|
||||
return outfit;
|
||||
}
|
||||
|
||||
this.unsubscribe = function (outfit) {
|
||||
|
|
Loading…
Reference in a new issue