Skip to content

Commit f6008bd

Browse files
authored
docs: add documentation comments to onAuthStateChange (#242)
1 parent 765b401 commit f6008bd

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Sources/Auth/AuthClient.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,18 @@ public actor AuthClient {
207207
}
208208

209209
/// Listen for auth state changes.
210+
/// - Parameter listener: Block that executes when a new event is emitted.
211+
/// - Returns: A handle that can be used to manually unsubscribe.
210212
///
211-
/// An `.initialSession` is always emitted when this method is called.
213+
/// - Note: This method blocks execution until the ``AuthChangeEvent/initialSession`` event is
214+
/// emitted. Although this operation is usually fast, in case of the current stored session being
215+
/// invalid, a call to the endpoint is necessary for refreshing the session.
212216
@discardableResult
213217
public func onAuthStateChange(
214218
_ listener: @escaping AuthStateChangeListener
215-
) -> AuthStateChangeListenerHandle {
219+
) async -> AuthStateChangeListenerHandle {
216220
let handle = eventEmitter.attachListener(listener)
217-
Task {
218-
await emitInitialSession(forHandle: handle)
219-
}
221+
await emitInitialSession(forHandle: handle)
220222
return handle
221223
}
222224

@@ -232,12 +234,14 @@ public actor AuthClient {
232234
session: Session?
233235
)>.makeStream()
234236

235-
let handle = onAuthStateChange { event, session in
236-
continuation.yield((event, session))
237-
}
237+
Task {
238+
let handle = await onAuthStateChange { event, session in
239+
continuation.yield((event, session))
240+
}
238241

239-
continuation.onTermination = { _ in
240-
handle.cancel()
242+
continuation.onTermination = { _ in
243+
handle.cancel()
244+
}
241245
}
242246

243247
return stream

Tests/AuthTests/AuthClientTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ final class AuthClientTests: XCTestCase {
5757
XCTAssertNil(handle, "handle should be deallocated")
5858
}
5959

60-
await Task.megaYield()
61-
6260
XCTAssertEqual(events.value, [.initialSession])
6361
}
6462
}

0 commit comments

Comments
 (0)