Table of Contents

Class EventSource<TEvent>

Namespace
LfrlAnvil.Reactive
Assembly
LfrlAnvil.Reactive.Core.dll

Represents a generic disposable event source that can be listened to.

public abstract class EventSource<TEvent> : IEventSource<TEvent>, IEventStream<TEvent>, IEventSource, IEventStream, IDisposable

Type Parameters

TEvent

Event type.

Inheritance
EventSource<TEvent>
Implements
IEventSource<TEvent>
IEventStream<TEvent>
Derived
Inherited Members
Extension Methods

Constructors

EventSource()

Creates a new EventSource<TEvent> instance.

protected EventSource()

Properties

HasSubscribers

Specifies whether this event source has any event subscribers.

public bool HasSubscribers { get; }

Property Value

bool

IsDisposed

Specifies whether this event stream has been disposed.

public bool IsDisposed { get; }

Property Value

bool

Subscribers

Collection of currently attached event subscribers to this event source.

public IEventSubscriber[] Subscribers { get; }

Property Value

IEventSubscriber[]

Methods

AcquireLock()

Acquires this event source's exclusive lock.

protected Lock.Scope AcquireLock()

Returns

Lock.Scope

Entered Lock.Scope of this event source.

Decorate<TNextEvent>(IEventListenerDecorator<TEvent, TNextEvent>)

Creates a new decorated IEventStream<TEvent> instance.

[Pure]
public IEventStream<TNextEvent> Decorate<TNextEvent>(IEventListenerDecorator<TEvent, TNextEvent> decorator)

Parameters

decorator IEventListenerDecorator<TEvent, TNextEvent>

Event listener decorator.

Returns

IEventStream<TNextEvent>

Decorated IEventStream<TEvent> instance.

Type Parameters

TNextEvent

Next event type.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public virtual void Dispose()

DisposeCore(out Chain<Exception>)

Performs safe disposal and cleans up all subscribers.

protected bool DisposeCore(out Chain<Exception> exceptions)

Parameters

exceptions Chain<Exception>

out parameter which returns all caught exceptions. Will always be empty when this method returns false.

Returns

bool

false when this event source was already disposed, otherwise true.

GetCurrentSubscribersUnsafe()

Gets all currently active subscribers and stores them into an array pool token.

protected ArrayPoolToken<IEventSubscriber> GetCurrentSubscribersUnsafe()

Returns

ArrayPoolToken<IEventSubscriber>

Array pool token containing all currently active subscribers.

Remarks

This method call is not thread-safe by default.

IsDisposedUnsafe()

Specifies whether this event stream has been disposed.

[Pure]
protected bool IsDisposedUnsafe()

Returns

bool

true when this event stream has been disposed, otherwise false.

Remarks

This method call is not thread-safe by default.

Listen(IEventListener<TEvent>)

Attaches the provided listener to this event stream.

public IEventSubscriber Listen(IEventListener<TEvent> listener)

Parameters

listener IEventListener<TEvent>

Event listener to attach.

Returns

IEventSubscriber

New IEventSubscriber instance that can be used to detach the listener.

NotifyListeners(ArrayPoolToken<IEventSubscriber>, TEvent)

Allows to notify all provided listeners via array pool token that an event has occurred.

protected Chain<Exception> NotifyListeners(ArrayPoolToken<IEventSubscriber> token, TEvent @event)

Parameters

token ArrayPoolToken<IEventSubscriber>

Array pool token containing subscribers to notify. This should be a token returned by GetCurrentSubscribersUnsafe() method.

event TEvent

Event to notify with.

Returns

Chain<Exception>

Collection of all caught exceptions.

OnSubscriberAddedUnsafe(IEventSubscriber, IEventListener<TEvent>)

Allows to react to attachment of a new event subscriber.

protected virtual void OnSubscriberAddedUnsafe(IEventSubscriber subscriber, IEventListener<TEvent> listener)

Parameters

subscriber IEventSubscriber

Attached event subscriber.

listener IEventListener<TEvent>

Event listener attached to the event subscriber.

Remarks

This method call is not thread-safe by default.

OnSubscriberRegistered(IEventSubscriber, IEventListener<TEvent>)

Allows to override an event listener after subscriber has been registered.

protected virtual IEventListener<TEvent> OnSubscriberRegistered(IEventSubscriber subscriber, IEventListener<TEvent> listener)

Parameters

subscriber IEventSubscriber

Event subscriber.

listener IEventListener<TEvent>

Event listener to override.

Returns

IEventListener<TEvent>

IEventListener<TEvent> instance.

OverrideListenerUnsafe(IEventSubscriber, IEventListener<TEvent>)

Allows to override an event listener.

protected virtual IEventListener<TEvent> OverrideListenerUnsafe(IEventSubscriber subscriber, IEventListener<TEvent> listener)

Parameters

subscriber IEventSubscriber

Event subscriber.

listener IEventListener<TEvent>

Event listener to override.

Returns

IEventListener<TEvent>

IEventListener<TEvent> instance.

Remarks

This method call is not thread-safe by default.

ThrowDisposedException()

Throws an exception when this event source has been disposed.

[DoesNotReturn]
protected void ThrowDisposedException()

Remarks

This method call is not thread-safe by default.

Exceptions

ObjectDisposedException

When this event source has been disposed.

TryNotifyListeners(TEvent)

Allows to notify all current event listeners that an event has occurred.

protected bool TryNotifyListeners(TEvent @event)

Parameters

event TEvent

Event to notify with.

Returns

bool

false when this event source was disposed and listeners were not notified, otherwise true.