Is it possible to somehow stop the propagation of an Announcement delivery?
Imagine:
Transcript open.
a := Announcer new.
a when: #event do: [ self logCr: 'first handler' ].
a when: #event do: [ self logCr: 'second handler' ].
a announce: #event.
When #event
has been announced, it will be delivered to all subscribers. The problem is, that I would like for one of the events to stop the propagation so the second one will not receive it. Similarly to the way event propagation can be stopped in JavaScript.
Unfortunately the way it is implemented (SubscriptionRegistry>>handlesAnnouncement:
) it first collects the subscribers and then it announces it.
No, that's currently not possible in Pharo. Your comparison with JavaScript is also not quite fair, since JavaScript is (effectively) single threaded, while Pharo is not. The current implementation of announcements does deliver an announcement in the same thread where it was triggered, so preventing further deliveries would be possible, but in the future the implementation may change to deliver announcements asynchronously. Then this problem will suddenly become much harder.