Skip to content

Commit 3a44f30

Browse files
authored
fix(realtime): add RealtimeSubscription and deprecate Subscription (#542)
1 parent ad06e27 commit 3a44f30

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

Sources/Realtime/V2/RealtimeChannelV2.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ extension Socket {
6464
}
6565

6666
public final class RealtimeChannelV2: Sendable {
67+
@available(*, deprecated, renamed: "RealtimeSubscription")
6768
public typealias Subscription = ObservationToken
6869

6970
public enum Status: Sendable {
@@ -464,9 +465,9 @@ public final class RealtimeChannelV2: Sendable {
464465
/// Listen for clients joining / leaving the channel using presences.
465466
public func onPresenceChange(
466467
_ callback: @escaping @Sendable (any PresenceAction) -> Void
467-
) -> Subscription {
468+
) -> RealtimeSubscription {
468469
let id = callbackManager.addPresenceCallback(callback: callback)
469-
return Subscription { [weak callbackManager, logger] in
470+
return RealtimeSubscription { [weak callbackManager, logger] in
470471
logger?.debug("Removing presence callback with id: \(id)")
471472
callbackManager?.removeCallback(id: id)
472473
}
@@ -479,7 +480,7 @@ public final class RealtimeChannelV2: Sendable {
479480
table: String? = nil,
480481
filter: String? = nil,
481482
callback: @escaping @Sendable (AnyAction) -> Void
482-
) -> Subscription {
483+
) -> RealtimeSubscription {
483484
_onPostgresChange(
484485
event: .all,
485486
schema: schema,
@@ -497,7 +498,7 @@ public final class RealtimeChannelV2: Sendable {
497498
table: String? = nil,
498499
filter: String? = nil,
499500
callback: @escaping @Sendable (InsertAction) -> Void
500-
) -> Subscription {
501+
) -> RealtimeSubscription {
501502
_onPostgresChange(
502503
event: .insert,
503504
schema: schema,
@@ -516,7 +517,7 @@ public final class RealtimeChannelV2: Sendable {
516517
table: String? = nil,
517518
filter: String? = nil,
518519
callback: @escaping @Sendable (UpdateAction) -> Void
519-
) -> Subscription {
520+
) -> RealtimeSubscription {
520521
_onPostgresChange(
521522
event: .update,
522523
schema: schema,
@@ -535,7 +536,7 @@ public final class RealtimeChannelV2: Sendable {
535536
table: String? = nil,
536537
filter: String? = nil,
537538
callback: @escaping @Sendable (DeleteAction) -> Void
538-
) -> Subscription {
539+
) -> RealtimeSubscription {
539540
_onPostgresChange(
540541
event: .delete,
541542
schema: schema,
@@ -553,7 +554,7 @@ public final class RealtimeChannelV2: Sendable {
553554
table: String?,
554555
filter: String?,
555556
callback: @escaping @Sendable (AnyAction) -> Void
556-
) -> Subscription {
557+
) -> RealtimeSubscription {
557558
precondition(
558559
status != .subscribed,
559560
"You cannot call postgresChange after joining the channel"
@@ -571,7 +572,7 @@ public final class RealtimeChannelV2: Sendable {
571572
}
572573

573574
let id = callbackManager.addPostgresCallback(filter: config, callback: callback)
574-
return Subscription { [weak callbackManager, logger] in
575+
return RealtimeSubscription { [weak callbackManager, logger] in
575576
logger?.debug("Removing postgres callback with id: \(id)")
576577
callbackManager?.removeCallback(id: id)
577578
}
@@ -581,9 +582,9 @@ public final class RealtimeChannelV2: Sendable {
581582
public func onBroadcast(
582583
event: String,
583584
callback: @escaping @Sendable (JSONObject) -> Void
584-
) -> Subscription {
585+
) -> RealtimeSubscription {
585586
let id = callbackManager.addBroadcastCallback(event: event, callback: callback)
586-
return Subscription { [weak callbackManager, logger] in
587+
return RealtimeSubscription { [weak callbackManager, logger] in
587588
logger?.debug("Removing broadcast callback with id: \(id)")
588589
callbackManager?.removeCallback(id: id)
589590
}

Sources/Realtime/V2/RealtimeClientV2.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public final class RealtimeClientV2: Sendable {
108108
/// - Note: Use ``statusChange`` if you prefer to use Async/Await.
109109
public func onStatusChange(
110110
_ listener: @escaping @Sendable (Status) -> Void
111-
) -> ObservationToken {
111+
) -> RealtimeSubscription {
112112
statusEventEmitter.attach(listener)
113113
}
114114

Sources/Realtime/V2/Types.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ public struct RealtimeClientOptions: Sendable {
6060
return String(accessToken)
6161
}
6262
}
63+
64+
public typealias RealtimeSubscription = ObservationToken

0 commit comments

Comments
 (0)