-
First, a big thank you for this amazing library! I am writing integration tests to test my app's interaction with the database. On app startup, a bunch of listeners to the database get initialized asynchronously. The problem is that I have to close the database connection by calling
Is there a way to somehow wait for queued queries to finish before closing the database? I saw mentions of similar issues here but that comment did not link to a solution. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Waiting for in-flight request before closing the database sounds reasonable, but that's not technically what's happening here. The error you've posted is thrown here, before submitting requests drift/drift/lib/src/remote/communication.dart Lines 127 to 130 in 4bd9fef For in-flight requests, you'd get a This actually makes it kind of tricky to fix this issue in drift. You have one asynchronous task closing the database and other independent tasks not realizing that and continuing to emit statements. Drift already closes streams when the database closes, but if you emit multiple statements in response to query streams updating, it's possible that the database closes in-between.
That's kind of tricky to set up, but I don't really see a solution that could live in drift. Judging from the error this isn't a weird intermediate half-closed state of the database internal to drift, you are closing the database and then have other tasks still using it. |
Beta Was this translation helpful? Give feedback.
Waiting for in-flight request before closing the database sounds reasonable, but that's not technically what's happening here. The error you've posted is thrown here, before submitting requests
drift/drift/lib/src/remote/communication.dart
Lines 127 to 130 in 4bd9fef
For in-flight requests, you'd get a
Channel was closed before receiving a response
error.This actually makes it kind of tricky to fix this issue in drift. You have one asynchronous task closing the database and other independent tasks not realizing that and continuing to emit stat…