-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename public API for room lifecycle and status
We: - rename the RoomLifecycle enum to RoomLifecycleStatus (which makes more sense); - rename the RoomStatus protocol to RoomLifecycle and rename its `current` property to `status` ("current" what?; it wasn’t clear, and was inconsistent with the core SDKs, which only use `current` for state _changes_) The net effect is that instead of writing `room.status.current` you now write `room.lifecycle.status`, which still seems pretty readable and gives the benefits listed above. This change has been agreed with the Chat team and the decision is recorded in [1]; they will make this change in JS. As part of this, I’ve also corrected references to room “state” to the correct terminology of “status” (in [2] Andy explains why they used the word “status”, choosing to reserve “state” for some larger composite state). Outstanding spec question about whether to rename the RoomInFailedState error [3]; that can wait. [1] https://ably.atlassian.net/wiki/spaces/CHA/pages/3307405320/SDK+Divergence+Decision+Log [2] #73 (comment) [3] https://github.com/ably/specification/pull/200/files#r1783542331
- Loading branch information
1 parent
be38b87
commit 64c0315
Showing
7 changed files
with
94 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@testable import AblyChat | ||
import Testing | ||
|
||
struct DefaultRoomLifecycleTests { | ||
@Test | ||
func current_startsAsInitialized() async { | ||
let lifecycle = DefaultRoomLifecycle(logger: TestLogger()) | ||
#expect(await lifecycle.status == .initialized) | ||
} | ||
|
||
@Test() | ||
func error_startsAsNil() async { | ||
let lifecycle = DefaultRoomLifecycle(logger: TestLogger()) | ||
#expect(await lifecycle.error == nil) | ||
} | ||
|
||
@Test | ||
func transition() async throws { | ||
// Given: A DefaultRoomLifecycle | ||
let lifecycle = DefaultRoomLifecycle(logger: TestLogger()) | ||
let originalStatus = await lifecycle.status | ||
let newStatus = RoomStatus.attached // arbitrary | ||
|
||
let subscription1 = await lifecycle.onChange(bufferingPolicy: .unbounded) | ||
let subscription2 = await lifecycle.onChange(bufferingPolicy: .unbounded) | ||
|
||
async let statusChange1 = subscription1.first { $0.current == newStatus } | ||
async let statusChange2 = subscription2.first { $0.current == newStatus } | ||
|
||
// When: transition(to:) is called | ||
await lifecycle.transition(to: newStatus) | ||
|
||
// Then: It emits a status change to all subscribers added via onChange(bufferingPolicy:), and updates its `status` property to the new status | ||
for statusChange in try await [#require(statusChange1), #require(statusChange2)] { | ||
#expect(statusChange.previous == originalStatus) | ||
#expect(statusChange.current == newStatus) | ||
} | ||
|
||
#expect(await lifecycle.status == .attached) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.