Skip to content

Commit

Permalink
resolve pending connect promises on unsubscribe to prevent throwing u…
Browse files Browse the repository at this point in the history
…nnecessary errors
  • Loading branch information
ganigeorgiev committed Jul 12, 2023
1 parent 5579854 commit 283499d
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.15.3

- Automatically resolve pending realtime connect `Promise`s in case `unsubscribe` is called before
`subscribe` is being able to complete ([pocketbase#2897](https://github.com/pocketbase/pocketbase/discussions/2897#discussioncomment-6423818)).


## 0.15.2

- Replaced `new URL(...)` with manual url parsing as it is not fully supported in React Native ([pocketbase#2484](https://github.com/pocketbase/pocketbase/discussions/2484#discussioncomment-6114540)).
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.15.2",
"version": "0.15.3",
"name": "pocketbase",
"description": "PocketBase JavaScript SDK",
"author": "Gani Georgiev",
Expand Down
10 changes: 7 additions & 3 deletions src/services/RealtimeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export default class RealtimeService extends BaseService {
for (let p of this.pendingConnects) {
p.reject(new ClientResponseError(err));
}
this.pendingConnects = [];
this.disconnect();
return;
}
Expand All @@ -399,10 +400,13 @@ export default class RealtimeService extends BaseService {
if (!fromReconnect) {
this.reconnectAttempts = 0;

// reject any remaining connect promises
const err = new ClientResponseError(new Error("Realtime disconnected."));
// resolve any remaining connect promises
//
// this is done to avoid unnecessary throwing errors in case
// unsubscribe is called before the pending connect promises complete
// (see https://github.com/pocketbase/pocketbase/discussions/2897#discussioncomment-6423818)
for (let p of this.pendingConnects) {
p.reject(err);
p.resolve();
}
this.pendingConnects = [];
}
Expand Down

0 comments on commit 283499d

Please sign in to comment.