Skip to content

Commit 4bd9fef

Browse files
committed
Document LazyDatabase limitation around isolates
1 parent 8eb5d38 commit 4bd9fef

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/docs/isolates.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ This can be helpful when using drift in dependency injection frameworks, since y
120120
to create the database instance synchronously.
121121
Internally, drift will connect when the first query is sent to the database.
122122

123+
!!! warning "Avoid connecting with `LazyDatabase`"
124+
125+
Parts of the drift documentation suggest `LazyDatabase` to setup a database connection
126+
asynchronously while still being able to return the database immediately.
127+
Using `LazyDatabase` to connect to a drift isolate that might have multiple clients (e.g.
128+
a UI isolate and a foreground worker) is not recommended as it only shares the executor
129+
responsible for running queries.
130+
`DatabaseConnection.delayed` ensures that stream queries are also synchronized.
131+
123132
### Workaround for old Flutter versions
124133

125134
Before Flutter 3.7, platforms channels weren't [available on background isolates](https://github.com/flutter/flutter/issues/13937).

0 commit comments

Comments
 (0)