Skip to content

Commit ce33bab

Browse files
committed
Fix closing the watch active attachments listener
1 parent 9ac685c commit ce33bab

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/attachments/src/AttachmentQueue.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AbstractPowerSyncDatabase, ILogger, Transaction } from '@powersync/common';
1+
import { AbstractPowerSyncDatabase, DifferentialWatchedQuery, ILogger, Transaction } from '@powersync/common';
22
import { AttachmentContext } from './AttachmentContext.js';
33
import { LocalStorageAdapter } from './LocalStorageAdapter.js';
44
import { RemoteStorageAdapter } from './RemoteStorageAdapter.js';
@@ -54,6 +54,8 @@ export class AttachmentQueue {
5454
/** Service for managing attachment-related database operations */
5555
attachmentService: AttachmentService;
5656

57+
watchActiveAttachments: DifferentialWatchedQuery<AttachmentRecord>;
58+
5759
/**
5860
* Creates a new AttachmentQueue instance.
5961
*
@@ -99,6 +101,7 @@ export class AttachmentQueue {
99101
this.tableName = tableName;
100102
this.syncingService = new SyncingService(this.context, localStorage, remoteStorage, logger ?? db.logger);
101103
this.attachmentService = new AttachmentService(tableName, db);
104+
this.watchActiveAttachments = this.attachmentService.watchActiveAttachments();
102105
this.syncIntervalMs = syncIntervalMs;
103106
this.syncThrottleDuration = syncThrottleDuration;
104107
this.downloadAttachments = downloadAttachments;
@@ -138,7 +141,7 @@ export class AttachmentQueue {
138141
}, this.syncIntervalMs);
139142

140143
// Sync storage when there is a change in active attachments
141-
this.attachmentService.watchActiveAttachments().registerListener({
144+
this.watchActiveAttachments.registerListener({
142145
onDiff: async () => {
143146
await this.syncStorage();
144147
}
@@ -247,7 +250,7 @@ export class AttachmentQueue {
247250
async stopSync(): Promise<void> {
248251
clearInterval(this.periodicSyncTimer);
249252
this.periodicSyncTimer = undefined;
250-
await this.attachmentService.watchActiveAttachments().close();
253+
await this.watchActiveAttachments.close();
251254
}
252255

253256
/**

0 commit comments

Comments
 (0)