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) -> ARTEventListenerParameters
eventThe named event to listen for.
callbackA callback invoked upon
eventwith anItemTypeobject, 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) -> ARTEventListenerParameters
callbackA callback invoked upon any event with an
ItemTypeobject, f.e.ARTConnectionStateChange.Return Value
The event listener.
-
Registers the provided listener for the first occurrence of a single named event specified as the
eventargument. 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) -> ARTEventListenerParameters
eventThe named event to listen for.
callbackA callback invoked upon
eventwith anItemTypeobject, 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) -> ARTEventListenerParameters
callbackA callback invoked upon any event with an
ItemTypeobject, 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
eventThe named event.
listenerThe 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
listenerThe event listener.
-
Deregisters all registrations, for all events and listeners.
Declaration
Objective-C
- (void)off;Swift
func off()
-
Emits an event, calling registered listeners with the given event name and any other given arguments. If an exception is raised in any of the listeners, the exception is caught by the
ARTEventEmitterand the exception is logged to the Ably logger. This method is internal and should not be called manually.Declaration
Objective-C
- (void)emit:(nullable EventType)event with:(nullable ItemType)data;Swift
func emit(_ event: EventType?, with data: ItemType?)Parameters
eventThe named event.
dataThe event payload.
-
Undocumented
Declaration
Objective-C
@property (nonatomic, readonly) NSNotificationCenter *notificationCenterSwift
var notificationCenter: NotificationCenter { get } -
Undocumented
Declaration
Objective-C
@property (nonatomic, readonly) dispatch_queue_t queueSwift
var queue: dispatch_queue_t { get } -
Undocumented
Declaration
Objective-C
@property (nullable, nonatomic, readonly) dispatch_queue_t userQueueSwift
var userQueue: dispatch_queue_t? { get } -
Undocumented
Declaration
Objective-C
@property (readonly) NSMutableDictionary<NSString *, NSMutableArray<ARTEventListener *> *> *listenersSwift
var listeners: NSMutableDictionary { get } -
Undocumented
Declaration
Objective-C
@property (readonly) NSMutableArray<ARTEventListener *> *anyListenersSwift
var anyListeners: NSMutableArray { get }