@@ -146,7 +146,25 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
146146 ) . port ;
147147 }
148148
149+ /**
150+ * Pass along any sync status updates to this listener
151+ */
152+ this . clientProvider = new SharedSyncClientProvider (
153+ this . webOptions ,
154+ ( status ) => {
155+ this . updateSyncStatus ( status ) ;
156+ } ,
157+ options . db
158+ ) ;
159+
149160 this . syncManager = Comlink . wrap < WorkerClient > ( this . messagePort ) ;
161+ /**
162+ * The sync worker will call this client provider when it needs
163+ * to fetch credentials or upload data.
164+ * This performs bi-directional method calling.
165+ */
166+ Comlink . expose ( this . clientProvider , this . messagePort ) ;
167+
150168 this . syncManager . setLogLevel ( this . logger . getLevel ( ) ) ;
151169
152170 this . triggerCrudUpload = this . syncManager . triggerCrudUpload ;
@@ -159,17 +177,6 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
159177 */
160178
161179 this . isInitialized = this . _init ( ) ;
162-
163- /**
164- * Pass along any sync status updates to this listener
165- */
166- this . clientProvider = new SharedSyncClientProvider (
167- this . webOptions ,
168- ( status ) => {
169- this . iterateListeners ( ( l ) => this . updateSyncStatus ( status ) ) ;
170- } ,
171- options . db
172- ) ;
173180 }
174181
175182 protected async _init ( ) {
@@ -190,30 +197,24 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
190197 // to free resources associated with this tab.
191198 // We take hold of this lock as soon-as-possible in order to cater for potentially closed tabs.
192199 getNavigatorLocks ( ) . request ( `tab-close-signal-${ crypto . randomUUID ( ) } ` , async ( lock ) => {
193- if ( ! this . abortOnClose . signal . aborted ) {
194- // Awaiting here ensures the worker is waiting for the lock
195- await this . syncManager . addLockBasedCloseSignal ( lock ! . name ) ;
200+ if ( this . abortOnClose . signal . aborted ) {
201+ return ;
202+ }
203+ // Awaiting here ensures the worker is waiting for the lock
204+ await this . syncManager . addLockBasedCloseSignal ( lock ! . name ) ;
196205
197- // The lock has been registered, we can continue with the initialization
198- resolve ( ) ;
206+ // The lock has been registered, we can continue with the initialization
207+ resolve ( ) ;
199208
200- await new Promise < void > ( ( r ) => {
201- this . abortOnClose . signal . onabort = ( ) => r ( ) ;
202- } ) ;
203- }
209+ await new Promise < void > ( ( r ) => {
210+ this . abortOnClose . signal . onabort = ( ) => r ( ) ;
211+ } ) ;
204212 } ) ;
205213 } ) ;
206214
207215 const { crudUploadThrottleMs, identifier, retryDelayMs } = this . options ;
208216 const flags = { ...this . webOptions . flags , workers : undefined } ;
209217
210- /**
211- * The sync worker will call this client provider when it needs
212- * to fetch credentials or upload data.
213- * This performs bi-directional method calling.
214- */
215- Comlink . expose ( this . clientProvider , this . messagePort ) ;
216-
217218 await this . syncManager . setParams (
218219 {
219220 dbParams : this . dbAdapter . getConfiguration ( ) ,
0 commit comments