Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-3630] feat: add ChannelStateChange.hasBacklog and return state change to attach promise/callback #1347

Merged
merged 2 commits into from Jun 29, 2023

Conversation

owenpearson
Copy link
Member

@owenpearson owenpearson commented Jun 22, 2023

Resolves #1328

See corresponding spec PR

These features in combination will allow users to check whether to expect a backlog of messages once attached to a realtime channel. In particular, when using rewind=1, this will allow users to create a promise which resolves once a channel is attached and, if applicable, the rewind message has been received.

@github-actions github-actions bot temporarily deployed to staging/pull/1347/features June 22, 2023 10:18 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/typedoc June 22, 2023 10:19 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/bundle-report June 22, 2023 10:20 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/features June 22, 2023 10:22 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/typedoc June 22, 2023 10:24 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/bundle-report June 22, 2023 10:24 Inactive
Copy link
Member

@SimonWoolf SimonWoolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection to the idea, seems like a reasonable feature.

There's nothing ably-js specific about this; if we think it's worth doing we should have a spec PR for this so it can eventually be done in all sdks (and added to api docs).

which resolves once a channel is attached and, if applicable, the rewind message has been received.

not sure I understand what the last part of that sentence means -- it resolves once the channel is attached full stop, no?

@owenpearson
Copy link
Member Author

owenpearson commented Jun 22, 2023

There's nothing ably-js specific about this; if we think it's worth doing we should have a spec PR for this so it can eventually be done in all sdks (and added to api docs).

@SimonWoolf Yeah we did consider this, my thinking was that this is unlikely to be needed in other SDKs so adding it to the spec would likely be futile. I'm kinda tempted to add it regardless though, will ask what the team thinks.

not sure I understand what the last part of that sentence means -- it resolves once the channel is attached full stop, no?

I'm not talking about any of the promises returned by the ably-js API here - the feature request was to make it possible to wait for a channel with rewind=1 to be attached and for the rewind message (if it exists) to be received, This wasn't possible before because there was no way to tell whether to expect a rewind message, but it should be now using the promise constructor. it wouldn't really make sense to add this promise to the library since it only works for rewind=1, any other rewind value has the possibility of a partial backlog.

@SimonWoolf
Copy link
Member

👍

my thinking was that this is unlikely to be needed in other SDKs so adding it to the spec would likely be futile

Shrug, I think there's still some value in formalising the API in the spec even if we're not imminently intending to implement in other sdks. there's other bits of the spec that are not-mandatory ("Libraries may offer a ClientOptions#agents property...", "Client libraries can optionally save a round-trip request to the Ably service for expired tokens by detecting when a token has expired...", etc)

it wouldn't really make sense to add this promise to the library since it only works for rewind=1, any other rewind value has the possibility of a partial backlog

yeah, really for that feature you'd need realtime to tell you when the backlog is finished, and tbh I'm not sure that that'd be a good idea. (also most sensible ways of returning another promise would involve a breaking api change, and would make it a very prominent part of the api, and istm it's not worth either of those)

@lawrence-forooghian
Copy link
Collaborator

I wasn't aware of the rewind feature, popping a link to the documentation here for future reference.

I think that exposing the hasBacklog property (which I can't find any documentation of, e.g. in the protocol spec — how did you find out about it?) makes sense, and if I've understood the use case correctly then I think it's a broadly useful thing, and hence worth including in the spec.

As for the change to the signature of attach, I wonder whether that needs to come alongside this change. For example, a user calling attach has, until now, had no direct way to access the ChannelStateChange.resumed property, which you can imagine a user might want to use to know whether they need to fetch channel history. I guess (please correct me if wrong) that our advice to users has been that to find this information out they need to listen for a channel state change using on, so would the same advice not apply here too? That said, if we are going to change the signature of attach then I think it should be a spec change, yeah.

@github-actions github-actions bot temporarily deployed to staging/pull/1347/features June 29, 2023 13:05 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/typedoc June 29, 2023 13:07 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/bundle-report June 29, 2023 13:07 Inactive
ably.d.ts Outdated Show resolved Hide resolved
ably.d.ts Outdated Show resolved Hide resolved
src/common/lib/client/realtimechannel.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to staging/pull/1347/features June 29, 2023 13:33 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/bundle-report June 29, 2023 13:34 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/typedoc June 29, 2023 13:35 Inactive
ably.d.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to staging/pull/1347/features June 29, 2023 13:53 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/typedoc June 29, 2023 13:55 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1347/bundle-report June 29, 2023 13:55 Inactive
Makes it so that `RealtimeChannel.attach` exposes the
`ChannelStateChange` via whatever async api (invoke callback or fulfill promise).
This makes it easy for users to access flags on the `ChannelStateChange`
to access information about the attachment.
Exposes the `hasBacklog` flag on `ChannelStateChange`. This may be used
in combination with rewind to check whether to expect a backlog of
messages upon attachment.
@owenpearson owenpearson merged commit 0514b7c into main Jun 29, 2023
9 of 10 checks passed
@owenpearson owenpearson deleted the has-backlog branch June 29, 2023 14:09
@hayleynewton hayleynewton changed the title feat: add ChannelStateChange.hasBacklog and return state change to attach promise/callback [SDK-3630] feat: add ChannelStateChange.hasBacklog and return state change to attach promise/callback Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

add ChannelStateChange.hasBacklog
3 participants