[GH-ISSUE #50] Properly closing live query #17

Closed
opened 2026-05-23 08:34:22 -06:00 by gitea-mirror · 7 comments
Owner

Originally created by @appy-one on GitHub (May 26, 2022).
Original GitHub issue: https://github.com/appy-one/acebase-client/issues/50

Originally assigned to: @appy-one on GitHub.

There currently is no way to stop a realtime query from delivering results, besides if returning false in one of the event callbacks. Waiting for a callback to happen might take a long time, so we need way to stop a realtime query upon request.

Suggestion:

const query = db.query('book').filter('rating', '==', ).on('add', bookAdded);
const snaps = await query.get();
// Some time later, stop the realtime query
await query.stop();

Discussed in https://github.com/appy-one/acebase/discussions/108

Originally posted by donl May 22, 2022
When a live query is no longer needed, what is the correct way to unsubscribe and destroy it?

Originally created by @appy-one on GitHub (May 26, 2022). Original GitHub issue: https://github.com/appy-one/acebase-client/issues/50 Originally assigned to: @appy-one on GitHub. There currently is no way to stop a realtime query from delivering results, besides if returning `false` in one of the event callbacks. Waiting for a callback to happen might take a long time, so we need way to stop a realtime query upon request. Suggestion: ```js const query = db.query('book').filter('rating', '==', ).on('add', bookAdded); const snaps = await query.get(); // Some time later, stop the realtime query await query.stop(); ``` ### Discussed in https://github.com/appy-one/acebase/discussions/108 <div type='discussions-op-text'> <sup>Originally posted by **donl** May 22, 2022</sup> When a live query is no longer needed, what is the correct way to unsubscribe and destroy it?</div>
gitea-mirror 2026-05-23 08:34:22 -06:00
Author
Owner

@appy-one commented on GitHub (Jun 6, 2022):

This has been added in acebase v1.21.0+ and acebase-client v1.16.0+ (or older version using latest acebase-core)

<!-- gh-comment-id:1357303960 --> @appy-one commented on GitHub (Jun 6, 2022): This has been added in acebase v1.21.0+ and acebase-client v1.16.0+ (or older version using latest acebase-core)
Author
Owner

@TELECI-PROJECT commented on GitHub (Sep 6, 2022):

Hi, I was trying out this today,

this is my setup:
acebase-server@1.11.0
acebase@1.21.7

I was connecting to AceBase server using a web app built on ReactJS with the browser client:
https://cdn.jsdelivr.net/npm/acebase-client@1.17.0/dist/browser.min.js

and I was able to run live query and get updates as described in the documentation.

This is my query:
this.db_listener = db.query('items')
.filter('locationid', '==', mylocationid)
.on('add', (match) => {
console.log("Item ADD");
}).on('remove', (match) => {
console.log("Item REMOVE");
}).on('change', (match) => {
console.log("Item CHANGE");
});

When I'm trying to stop the live query with this:
await this.db_listener.stop();

I see this kind of error in console:
Uncaught (in promise) ReferenceError: socket is not defined
stop browser.min.js:16
stop browser.min.js:16
componentWillUnmount MyComponent.jsx:119

<!-- gh-comment-id:1357303962 --> @TELECI-PROJECT commented on GitHub (Sep 6, 2022): Hi, I was trying out this today, this is my setup: acebase-server@1.11.0 acebase@1.21.7 I was connecting to AceBase server using a web app built on ReactJS with the browser client: https://cdn.jsdelivr.net/npm/acebase-client@1.17.0/dist/browser.min.js and I was able to run live query and get updates as described in the documentation. This is my query: this.db_listener = db.query('items') .filter('locationid', '==', mylocationid) .on('add', (match) => { console.log("Item ADD"); }).on('remove', (match) => { console.log("Item REMOVE"); }).on('change', (match) => { console.log("Item CHANGE"); }); When I'm trying to stop the live query with this: await this.db_listener.stop(); I see this kind of error in console: Uncaught (in promise) ReferenceError: socket is not defined stop browser.min.js:16 stop browser.min.js:16 componentWillUnmount MyComponent.jsx:119
Author
Owner

@appy-one commented on GitHub (Sep 8, 2022):

Thanks for reporting, I'll look into it asap

<!-- gh-comment-id:1357303967 --> @appy-one commented on GitHub (Sep 8, 2022): Thanks for reporting, I'll look into it asap
Author
Owner

@appy-one commented on GitHub (Dec 19, 2022):

I'm moving this issue to the acebase client repo

<!-- gh-comment-id:1357303970 --> @appy-one commented on GitHub (Dec 19, 2022): I'm moving this issue to [the acebase client repo](https://github.com/appy-one/acebase-client)
Author
Owner

@appy-one commented on GitHub (Dec 19, 2022):

Looks like I was too quick to draw - this originally was an acebase issue. @TELECI-PROJECT you were have an issue using acebase-client v1.17.0 browser dist. Have you updated to the latest version to check if the issue has been resolved in the meantime?

<!-- gh-comment-id:1357307871 --> @appy-one commented on GitHub (Dec 19, 2022): Looks like I was too quick to draw - this originally was an `acebase` issue. @TELECI-PROJECT you were have an issue using `acebase-client` v1.17.0 browser dist. Have you updated to the latest version to check if the issue has been resolved in the meantime?
Author
Owner

@TELECI-PROJECT commented on GitHub (Dec 22, 2022):

Hi, thanks, I don't see any errors in console after updating to the latest version (Acebase Client v1.20 and Acebase v1.27).

<!-- gh-comment-id:1363271766 --> @TELECI-PROJECT commented on GitHub (Dec 22, 2022): Hi, thanks, I don't see any errors in console after updating to the latest version (Acebase Client v1.20 and Acebase v1.27).
Author
Owner

@appy-one commented on GitHub (Dec 23, 2022):

Great!

Spread the word contribute Sponsor AceBase

<!-- gh-comment-id:1363695984 --> @appy-one commented on GitHub (Dec 23, 2022): Great! [![Spread the word](https://user-images.githubusercontent.com/26569719/169265089-3d593555-e1ad-4390-986b-877ac2c38a47.svg)](https://twitter.com/intent/tweet?button=&url=https://github.com/appy-one/acebase&text=I'm+using+@AcebaseRealtime+in+my+project+to+make+my+life+easier!&button=) [![contribute](https://user-images.githubusercontent.com/26569719/169265318-30c4c6a5-7c89-46a0-a7a2-ef433a8192f4.svg)](https://github.com/appy-one/acebase#contributing) [![Sponsor AceBase](https://user-images.githubusercontent.com/26569719/168233053-8e56b243-4140-40ab-9a30-4cb3cc149bfe.svg)](https://github.com/sponsors/appy-one)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase-client#17
No description provided.