You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
unsafePullChangesAsyncGenerator is an alternative to pullChanges (now
made optional), that returns an AsyncGenerator of PullResults. This
should make large updates/initial syncs more tractable as the sync can
be split up into several smaller chunks.
1. Updated TS types to be robust discriminated union (i.e. either
pullChanges OR unsafePullChangesAsyncGenerator HAVE to be present)
2. Updated Flow types to make pullChanges and
unsafePullChangesAsyncGenerator optional
3. Added an invariant check to ensure there is at least one pull
strategy provided (for JS lads)
4. Added code that "lifts" the result from pullChanges into an
AsyncGenerator - ensuring only 1 code path going forward
5. Added a loop that pulls of the generator and performs DB writes
until the generator is exhausted.
6. Added tests
7. Added babel support for async generators
invariant(false,'Either pullChanges or unsafePullChangesAsyncGenerator must be provided')
61
64
}
62
65
63
-
awaitdatabase.write(async()=>{
64
-
ensureSameDatabase(database,resetCount)
65
-
invariant(
66
-
lastPulledAt===(awaitgetLastPulledAt(database)),
67
-
'[Sync] Concurrent synchronization is not allowed. More than one synchronize() call was running at the same time, and the later one was aborted before committing results to local database.',
68
-
)
66
+
letnewLastPulledAt: Timestamp|null=null
67
+
letresult=awaitpullChunks.next()
68
+
log&&(log.phase='pulled')
69
+
70
+
// To answer your question - yes it would be nice to use a for await loop here
71
+
// however, because of the use of 'fast-async' (see babel config), this syntax is *not* supported and will cause the code to hang...
72
+
while(!result.done){
73
+
constpullResult=result.value
74
+
let chunkNewLastPulledAt: Timestamp=(pullResult: any).timestamp
75
+
newLastPulledAt=chunkNewLastPulledAt
76
+
constremoteChangeCount=pullResult.changes ? changeSetCount(pullResult.changes) : NaN
'unsafeTurbo must not be used with _unsafeBatchPerCollection',
85
+
lastPulledAt===(awaitgetLastPulledAt(database)),
86
+
'[Sync] Concurrent synchronization is not allowed. More than one synchronize() call was running at the same time, and the later one was aborted before committing results to local database.',
74
87
)
88
+
89
+
if(unsafeTurbo){
90
+
invariant(
91
+
!_unsafeBatchPerCollection,
92
+
'unsafeTurbo must not be used with _unsafeBatchPerCollection',
93
+
)
94
+
invariant(
95
+
'syncJson'inpullResult||'syncJsonId'inpullResult,
96
+
'missing syncJson/syncJsonId',
97
+
)
98
+
invariant(lastPulledAt===null,'unsafeTurbo can only be used as the first sync')
0 commit comments