ARTEventEmitter
Objective-C
@interface ARTEventEmitter<EventType : id <ARTEventIdentification>, ItemType>
: NSObject
Swift
class ARTEventEmitter<EventType, ItemType> : NSObject, @unchecked Sendable where EventType : ARTEventIdentification, ItemType : AnyObject
A generic interface for event registration and delivery used in a number of the types in the Realtime client library. For example, the ARTConnection
and ARTRealtimeChannel
objects emit events for their state using the ARTEventEmitter
pattern.
-
Registers the provided listener for the specified event. If
on:callback:
is called more than once with the same listener and event, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice usingon:callback:
, and an event is emitted once, the listener would be invoked twice.Declaration
Objective-C
- (nonnull ARTEventListener *)on:(nonnull EventType)event callback:(nonnull void (^)(ItemType _Nonnull))callback;
Swift
func on(_ event: EventType, callback: @escaping (ItemType) -> Void) -> ARTEventListener
Parameters
event
The named event to listen for.
callback
A callback invoked upon
event
with anItemType
object, f.e.ARTConnectionStateChange
.Return Value
The event listener.
-
Registers the provided listener all events. If
on:
is called more than once with the same listener and event, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice usingon:
, and an event is emitted once, the listener would be invoked twice.Declaration
Objective-C
- (nonnull ARTEventListener *)on:(nonnull void (^)(ItemType _Nonnull))callback;
Swift
func on(_ callback: @escaping (ItemType) -> Void) -> ARTEventListener
Parameters
callback
A callback invoked upon any event with an
ItemType
object, f.e.ARTConnectionStateChange
.Return Value
The event listener.
-
Registers the provided listener for the first occurrence of a single named event specified as the
event
argument. Ifonce:callback:
is called more than once with the same listener, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice usingonce:callback:
, and an event is emitted once, the listener would be invoked twice. However, all subsequent events emitted would not invoke the listener asonce:callback:
ensures that each registration is only invoked once.Declaration
Objective-C
- (nonnull ARTEventListener *)once:(nonnull EventType)event callback: (nonnull void (^)(ItemType _Nonnull))callback;
Swift
func once(_ event: EventType, callback: @escaping (ItemType) -> Void) -> ARTEventListener
Parameters
event
The named event to listen for.
callback
A callback invoked upon
event
with anItemType
object, f.e.ARTConnectionStateChange
.Return Value
The event listener.
-
Registers the provided listener for the first event that is emitted. If
once:
is called more than once with the same listener, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice usingonce:
, and an event is emitted once, the listener would be invoked twice. However, all subsequent events emitted would not invoke the listener asonce:
ensures that each registration is only invoked once.Declaration
Objective-C
- (nonnull ARTEventListener *)once: (nonnull void (^)(ItemType _Nonnull))callback;
Swift
func once(_ callback: @escaping (ItemType) -> Void) -> ARTEventListener
Parameters
callback
A callback invoked upon any event with an
ItemType
object, f.e.ARTConnectionStateChange
.Return Value
The event listener.
-
Removes all registrations that match both the specified listener and the specified event.
Declaration
Objective-C
- (void)off:(nonnull EventType)event listener:(nonnull ARTEventListener *)listener;
Swift
func off(_ event: EventType, listener: ARTEventListener)
Parameters
event
The named event.
listener
The event listener.
-
Deregisters the specified listener. Removes all registrations matching the given listener, regardless of whether they are associated with an event or not.
Declaration
Objective-C
- (void)off:(nonnull ARTEventListener *)listener;
Swift
func off(_ listener: ARTEventListener)
Parameters
listener
The event listener.
-
Deregisters all registrations, for all events and listeners.
Declaration
Objective-C
- (void)off;
Swift
func off()