Subscription

When you add a new subscriber to your EventStream or Signal, in return you get a Subscription. A subscription can then be used to inform the source about changes in the condition of the connection: should it be enabled or disabled, should the subscriber be subscribed or (temporarily) unsubscribed, or should the subscription be permanently destroyed.

When you add a new subscriber to your EventStream or Signal, in return you get a Subscription. A subscription can then be used to inform the source about changes in the condition of the connection: should it be enabled or disabled, should the subscriber be subscribed or (temporarily) unsubscribed, or should the subscription be permanently destroyed.

It is important to destroy subscriptions when they are no longer needed, e.g. at the end of the life of an object which subscribes to the source of events. Otherwise you may face a hidden memory leak where no longer used data cannot be GC-ed because it is still referenced by the source of events.

See also

EventContext Implement this trait together with writing a new event source if you want to change how your event source reacts to the aforementioned events. For an example of how to do it on a small scale, please

class Object
trait Matchable
class Any

Value members

Abstract methods

def destroy(): Unit

Should be called when the subscription is no longer needed.

Should be called when the subscription is no longer needed.

def disable(): Unit

You can think of enable()/disable() as of subscribe()/unsubscribe() on a higher level. In the default implementation, enable() is called automatically when the subscription is created, and it calls subscribe(). Later, the subscriber can disable() the subscription, which will call unsubscribe(). If the subscriber simply calls unsubscribe() without disabling, nothing will happen.

You can think of enable()/disable() as of subscribe()/unsubscribe() on a higher level. In the default implementation, enable() is called automatically when the subscription is created, and it calls subscribe(). Later, the subscriber can disable() the subscription, which will call unsubscribe(). If the subscriber simply calls unsubscribe() without disabling, nothing will happen.

In practice, usually you should use enable()/disable() for temporarily stopping and restarting, and use subscribe()/unsubscribe() only in custom event contexts.

See also

In the default implementation, you can call this to prevent the subscriber from unsubscribing. The subscription will stay subscribed until destroyed.

In the default implementation, you can call this to prevent the subscriber from unsubscribing. The subscription will stay subscribed until destroyed.

def enable(): Unit

You can think of enable()/disable() as of subscribe()/unsubscribe() on a higher level. In the default implementation, enable() is called automatically when the subscription is created, and it calls subscribe(). Later, the subscriber can unsubscribe() but the subscription will stay enabled, whereas if the subscriber calls disable(), it will in turn call unsubscribe(), but a simple re-subscribing will not work - instead, the subscriber will have to work enable() again.

You can think of enable()/disable() as of subscribe()/unsubscribe() on a higher level. In the default implementation, enable() is called automatically when the subscription is created, and it calls subscribe(). Later, the subscriber can unsubscribe() but the subscription will stay enabled, whereas if the subscriber calls disable(), it will in turn call unsubscribe(), but a simple re-subscribing will not work - instead, the subscriber will have to work enable() again.

In practice, enable()/disable() make sense if you work with custom EventContext. Otherwise you can use subscribe()/unsubscribe() instead.

See also
def subscribe(): Unit

Should be called automatically when a new subscriber is added to the event source. Can be called manually if the subscriber unsubscribed, but is still enabled, and now it wants again to receive events.

Should be called automatically when a new subscriber is added to the event source. Can be called manually if the subscriber unsubscribed, but is still enabled, and now it wants again to receive events.

def unsubscribe(): Unit

Use to stop receiving events but still maintain the possibility to re-subscribe.

Use to stop receiving events but still maintain the possibility to re-subscribe.