Skip to content

Commit 1ea8059

Browse files
committed
Ensure channel no longer attaching when detaching
1 parent 03f111f commit 1ea8059

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

javascript_client/src/subscriptions/createAblyHandler.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ function createAblyHandler(options: AblyHandlerOptions) {
135135
const disposedChannel = channel
136136
disposedChannel.unsubscribe()
137137

138+
// Ensure channel is no longer attaching, as otherwise detach does
139+
// nothing
140+
if (disposedChannel.state === "attaching") {
141+
await new Promise((resolve, _reject) => {
142+
const onStateChange = (
143+
stateChange: Types.ChannelStateChange
144+
) => {
145+
if (stateChange.current !== "attaching") {
146+
disposedChannel.off(onStateChange)
147+
resolve()
148+
}
149+
}
150+
disposedChannel.on(onStateChange)
151+
})
152+
}
153+
138154
await new Promise((resolve, reject) => {
139155
disposedChannel.detach((err: Types.ErrorInfo) => {
140156
if (err) {

0 commit comments

Comments
 (0)