Skip to content

Commit

Permalink
feat: Add instance level support for swift concurrency on `PortalsPub…
Browse files Browse the repository at this point in the history
…Sub` (#81)
  • Loading branch information
Steven0351 authored Jan 16, 2024
1 parent 406e80f commit 833b772
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sources/IonicPortals/PortalsPlugin+SwiftConcurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ import Foundation

#if compiler(>=5.6) && canImport(_Concurrency)
extension PortalsPubSub {
/// Subscribe to a topic and receive the events in an `AsyncStream`
/// Subscribe to a topic and receive the events in an `AsyncStream`. Uses ``shared`` to subscribe.
/// - Parameter topic: The topic to subscribe to
/// - Returns: An AsyncStream emitting ``SubscriptionResult``
public static func subscribe(to topic: String) -> AsyncStream<SubscriptionResult> {
PortalsPubSub.shared.subscribe(to: topic)
}

/// Subscribe to a topic and receive the events in an `AsyncStream`
/// - Parameter topic: The topic to subscribe to
/// - Returns: An AsyncStream emitting ``SubscriptionResult``
public func subscribe(to topic: String) -> AsyncStream<SubscriptionResult> {
AsyncStream { continuation in
let cancellable = PortalsPubSub.subscribe(to: topic) { result in
let cancellable = subscribe(to: topic) { result in
continuation.yield(result)
}

Expand Down

0 comments on commit 833b772

Please sign in to comment.