Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add connection and channel whenState methods
These methods were added in ably-js a long time ago (first mention is in commit 55b1be4 there), being described as an "undocumented feature" used by a test case. We seem to now consider them a part of the public API of ably-js; for example, they were added to the TypeScript typings in [1]. The implemention of these methods, however, is inconsistent and flawed. As of ably-js commit 64caf8e: - when Connection is already in the given state, whenState synthesises a state change, and this state change is invalid (see [2]) - on the other hand, when RealtimeChannel is already in the given state, whenState emits a nullish state change, contrary to what its signature claims (see [3]) I suggested in [4] that we simply remove these methods in ably-js v2, but Simon indicated that he considers these to be useful APIs worth considering keeping: > IMO it's quite useful to be able to write `await > realtime.connection.whenState('connected');` without having to worry about the > edge case that the connection is already connected. So, here I add them to the specification so that we can agree on the intended behaviour and then test the implementation. I’ve chosen to emit a null state change when the receiver is already in the given state. This is in line with the already-attached behaviour described for `RealtimeChannel#attach()` in RTL4d1, and I think makes more sense than the alternatives of trying to synthesise a state change, or returning the state change that led to the given state (this latter approach wouldn’t work for the initial state anyway). We’ll implement the behaviour specified here in ably-js v2, and I’ll figure out what’s the best we can do in v1. [1] ably/ably-js#444 [2] ably/ably-js#1599 [3] ably/ably-js#1598 [4] ably/ably-js#1597
- Loading branch information