Effect
public struct Effect<Event>
extension Effect: AsyncSequence
-
Initialize an effect that will emit a single event.
Declaration
Swift
public init( id: String = UUID().uuidString, closure: @escaping () async -> Event? )
Parameters
id
The ID of the efect. Default value:
UUID().uuidString
.closure
The effect’s function.
-
Initialize an effect that can emit unlimited events.
Use this initializer if your effect can emit multiple events. For example: - Location monitor. - Streaming values (e.g. websockets) - Audio player position monitoring.
Declaration
Swift
public init( id: String = UUID().uuidString, closure: @escaping (_ emit: (Event) -> Void, _ finish: () -> Void) async -> Void )
Parameters
id
The ID of the efect. Default value:
UUID().uuidString
.closure
The effect’s function. The closure provides you with two closures. The first one,
emit
, should be used to emit events. The secondfinish
, should be called when/if the effect finishes. -
Initialize an effect that emits a single event.
Declaration
Swift
public init(_ event: Event)
Parameters
event
The event to emit.
-
Declaration
Swift
public typealias Element = Event
-
Declaration
Swift
public func makeAsyncIterator() -> AnyAsyncSequenceable<Element>
-
Creates a fire and forget effect. This effect will not emit any events and will finish as soon as the provided closure has been executed.
Declaration
Swift
public static func fireAndForget(_ closure: @escaping () async -> Void) -> Effect<Event>
Parameters
closure
An async closure.
Return Value
An effect.
-
Create a cancel effect that can be used to cancel a long running effect.
Declaration
Swift
public static func cancel(_ id: String) -> Effect<Event>
Parameters
id
The ID of the effect to cancel.
Return Value
An effect.