Self-removing announcement subscription?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Self-removing announcement subscription?

Jan Blizničenko
Hi all

Today I come with a question regarding announcements.
I would like to make announcement subscription which would remove itself after first use.
Something like...

anObject announcer
    subscribe: TRMouseDragEnd
    do: [ :event |
        self thisMethodWith: differentParameters.
        "anObject announcer removeSubscription: ...this one..." ].

All I was able to do is write there
 anObject announcer unsubscribe: self.
which somehow works, but this instance could have multiple subscriptions and it would remove even those I don't want to remove, I need to remove only this specific one...

Jan
Reply | Threaded
Open this post in threaded view
|

Re: Self-removing announcement subscription?

Henrik Sperre Johansen

On 25 Oct 2014, at 2:42 , Jan B. <[hidden email]> wrote:

Hi all

Today I come with a question regarding announcements.
I would like to make announcement subscription which would remove itself
after first use.
Something like...

anObject announcer
   subscribe: TRMouseDragEnd
   do: [ :event |
       self thisMethodWith: differentParameters.
       "anObject announcer removeSubscription: ...this one..." ].

All I was able to do is write there
anObject announcer unsubscribe: self.
which somehow works, but this instance could have multiple subscriptions and
it would remove even those I don't want to remove, I need to remove only
this specific one...

Jan



--
View this message in context: http://forum.world.st/Self-removing-announcement-subscription-tp4786622.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Modify:
AnnouncementSubscription >> #deliver: 
" deliver an announcement to receiver. In case of failure, it will be handled in separate process"

^ (self handlesAnnouncement: anAnnouncement ) ifTrue: [
[action cull: anAnnouncement cull: announcer cull: self
on: UnhandledError fork: [:ex | ex pass ]]

and you could use the block:
[:event :announcer :sub |
self thisMethodWith: differentParameters
announcer removeSubscription: sub ]

VW already does this for their announcement implementation, it might be a good idea to introduce the third parameter in stock Pharo as well.

Cheers,
Henry
Reply | Threaded
Open this post in threaded view
|

Re: Self-removing announcement subscription?

Francisco Garau-2
In reply to this post by Jan Blizničenko
Just a thought, but wouldn't it better to have a method called #subscribeOnce:do: and let it handle the subscription removal?

- Francisco


> On 25 Oct 2014, at 13:42, "Jan B." <[hidden email]> wrote:
>
> Hi all
>
> Today I come with a question regarding announcements.
> I would like to make announcement subscription which would remove itself
> after first use.
> Something like...
>
> anObject announcer
>    subscribe: TRMouseDragEnd
>    do: [ :event |
>        self thisMethodWith: differentParameters.
>        "anObject announcer removeSubscription: ...this one..." ].
>
> All I was able to do is write there
> anObject announcer unsubscribe: self.
> which somehow works, but this instance could have multiple subscriptions and
> it would remove even those I don't want to remove, I need to remove only
> this specific one...
>
> Jan
>
>
>
> --
> View this message in context: http://forum.world.st/Self-removing-announcement-subscription-tp4786622.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>