Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The work from #25 introduced
waitForReady
on the PowerSyncDatabase client. This function should resolve once the client has been fully initialised.The
waitForReady
method was previously responsible for setting theAbstractPowerSyncDatabase.ready
member, but theinitialized
listener would only be registered oncewaitForReady
had been called. If theinit
function had been called and completed before anywaitForReady
calls were made: the executedwaitForReady
function would never resolve as theinitialized
event would not be triggered again (init was already completed).This issue was initially not detected in testing as (a logged in) test app contains watched queries which triggered
waitForReady
and correctly configured theinitialized
listener beforeinit
had completed. This bug is however relevant when completing the signin flow as no queries are awaited before theinit
call is made.Fix
The API now follows the Flutter SDK by automatically calling the
initialize
method when the client is constructed. Theinit
method now also follows the FlutterSDK by usingwaitForReady
to allow catching any errors during initialisation and await intitialzation,waitForReady
is still used throughout the implementation as it's name is more indicative of its function.