Bus
class Bus
A Bus for events to go from publishers to subscribers
-
A name for the bus.
Declaration
Swift
public private(set) var label: String { get }
-
Queue on which to execute publish/subscribe actions to ensure thread safety
Declaration
Swift
public private(set) var queue: DispatchQueue { get }
-
Initialize a Causality Event Bus
Declaration
Swift
public init(label: String, queue: DispatchQueue = globalQueue)
Parameters
label
name to give the bus
queue
Queue for bookkeeping (e.g. to ensure publish/subscribe is thread safe)
-
Publish an event to the bus.
All subscribers to this event will have their handler called along with the associated message.
Declaration
Parameters
event
Event to publish
message
Message to send in event
-
Add a subscriber to a specific event type
Declaration
Parameters
event
The event to subscribe to.
queue
DispatchQueue to receive messages on. This will take precedence over any queue specified by the publisher.
handler
A handler that is called for each event of this type that occurs (on the specified queue)
-
Add a subscriber to a specific event type
Declaration
Parameters
event
The event to subscribe to.
queue
OperationQueue to receive messages on. This will take precedence over any queue specified by the publisher.
handler
A handler that is called for each event of this type that occurs (on the specified queue)
-
Add a subscriber to an event
Declaration
Parameters
event
The event to subscribe to.
queue
DispatchQueue to receive messages on. This will take precedence over any queue specified by the publisher.
handler
A handler that is called for each event of this type that occurs (on the specified queue)
Return Value
Subscription handle that is needed to unsubscribe to this event
-
Add a subscriber to an event
Declaration
Parameters
event
The event to subscribe to.
queue
OperationQueue to receive messages on. This will take precedence over any queue specified by the publisher.
handler
A handler that is called for each event of this type that occurs (on the specified queue)
Return Value
Subscription handle that is needed to unsubscribe to this event
-
Stop a particular subscription handler from listening to events anymore.
Declaration
Parameters
subsription
The Subscription that was returned from
subscribe()
-
Publish an event to the bus.
All subscribers to this event will have their handler called along with the associated message.
Declaration
Parameters
state
The state to set the value for
value
The value to set for the given state
-
Add a subscriber to a specific state type
Declaration
Parameters
state
The state to subscribe to.
queue
DispatchQueue to receive messages on. This will take precedence over any queue specified by the publisher.
handler
A handler that is called for each event of this type that occurs (on the specified queue)
-
Add a subscriber to a specific state type
Declaration
Parameters
state
The state to subscribe to.
queue
OperationQueue to receive messages on. This will take precedence over any queue specified by the publisher.
handler
A handler that is called for each event of this type that occurs (on the specified queue)
-
Add a subscriber to a specific state type
Declaration
Parameters
state
The state to subscribe to.
queue
DispatchQueue to receive messages on. This will take precedence over any queue specified by the publisher.
handler
A handler that is called for each event of this type that occurs (on the specified queue)
-
Add a subscriber to a specific state type
Declaration
Parameters
state
The event type to subscribe to.
queue
OperationQueue to receive messages on. This will take precedence over any queue specified by the publisher.
handler
A handler that is called for each event of this type that occurs (on the specified queue)
-
Stop a particular subscription handler from listening to state changes anymore.
Declaration
Parameters
subscription
The Subscription that was returned from
subscribe()