Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#14945 closed defect (invalid)

Topic.publish() should return a deferred.

Reported by: omega Owned by: omega
Priority: undecided Milestone: tbd
Component: Events Version: 1.7.2
Keywords: Cc:
Blocked By: Blocking:

Description

It would be nice if I could queue stuff to happen after a topic notification has run its course.

Right now to work around this, I'm queueing the origin as the "last" interested party in the topic by registering it just prior to emitting the topic.

As I mentioned, this is clearly a workaround as it's not as direct as simply being able to go ".then(...)" after broadcasting on a topic. It would also make the code easier to follow...

Code examples:

...

unimportantMethod: function () {

topic.subscribe("sprinkles!", dojo.hitch(this, this.onSprinkles));

topic.publish("sprinkles!", []);

topic.publish("sprinkles!").then(dojo.hitch(this, this.onSprinkes));

},

onSprinkles: function (lovesSprinkles) {

console.log("These people loved sprinkles:");

console.log(lovesSprinkles);

},

...

The second example in "unimportantMethod" would be preferable.

Change History (4)

comment:1 Changed 8 years ago by bill

Component: GeneralEvents
Owner: set to omega
Status: newpending

Isn't publish() synchronous? It's strange to return a Deferred from a synchronous operation. Can't you just do this?

topic.publish("sprinkles!", []);
this.onSprinkles();

comment:2 Changed 8 years ago by ben hockey

+1 publish is synchronous - no need to return a Deferred. if certain subscribers are doing something asynchronous then that's outside the scope of what publish manages.

bill, should we just close as invalid?

comment:3 Changed 8 years ago by bill

Resolution: invalid
Status: pendingclosed

Sure.

comment:4 Changed 8 years ago by omega

I don't need async, so that's fine. I didn't know it was sync though, thanks!

Note: See TracTickets for help on using tickets.