Publisher
enum Publisher
Get Combine Publishers for Amplify APIs.
Provides static methods to create Combine Publishers from Tasks and AsyncSequences.
These can be used to get Combine Publishers for any Amplify API.
-
Create a Combine Publisher for a given Task.
Example Usage
let sink = Amplify.Publisher.create { try await Amplify.Geo.search(for "coffee") } .sink { completion in // handle completion } receiveValue: { value in // handle value }
Declaration
Swift
public static func create<Success>( _ operation: @escaping @Sendable () async throws -> Success ) -> AnyPublisher<Success, Error>
Parameters
operation
The Task for which to create the Publisher.
Return Value
The Publisher for the given Task.
-
Create a Combine Publisher for a given non-throwing Task.
Example Usage
let sink = Amplify.Publisher.create { try await Amplify.Auth.signOut() } .sink(receiveValue: { value in // handle value })
Declaration
Swift
public static func create<Success>( _ operation: @escaping @Sendable () async -> Success ) -> AnyPublisher<Success, Never>
Parameters
operation
The Task for which to create the Publisher.
Return Value
The Publisher for the given Task.
-
Create a Combine Publisher for a given AsyncSequence.
Example Usage
let subscription = Amplify.API.subscribe( request: .subscription(of: Todo.self, type: .onCreate) ) let sink = Amplify.Publisher.create(subscription) .sink { completion in // handle completion } receiveValue: { value in // handle value }
Declaration
Swift
public static func create<Sequence: AsyncSequence>( _ sequence: Sequence ) -> AnyPublisher<Sequence.Element, Error>
Parameters
sequence
The AsyncSequence for which to create the Publisher.
Return Value
The Publisher for the given AsyncSequence.