#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 9 years ago by
Component: | General → Events |
---|---|
Owner: | set to omega |
Status: | new → pending |
comment:2 Changed 9 years ago by
+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:4 Changed 9 years ago by
I don't need async, so that's fine. I didn't know it was sync though, thanks!
Isn't publish() synchronous? It's strange to return a Deferred from a synchronous operation. Can't you just do this?