Skip to content

Document sharing one DriftIsolate via IsolateNameServer #2095 - #3846

Open
AzazelSensei wants to merge 1 commit into
simolus3:developfrom
AzazelSensei:docs/2095-isolate-name-server
Open

Document sharing one DriftIsolate via IsolateNameServer #2095#3846
AzazelSensei wants to merge 1 commit into
simolus3:developfrom
AzazelSensei:docs/2095-isolate-name-server

Conversation

@AzazelSensei

Copy link
Copy Markdown

People hitting this usually spawn a DriftIsolate in the UI and again in a background service. Those are two databases, so watch() in the foreground never sees the background writes.

This adds that warning to the independent-isolates section, plus the lookup-or-spawn snippet using IsolateNameServer that you already confirmed on the issue. Flutter apps in the same engine can keep using shareAcrossIsolates: true instead.

Fixes #2095

Calling spawn from both the UI and a background worker creates two
databases, so watch() on one side never sees the other side's writes.

Fixes simolus3#2095

@simolus3 simolus3 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving documentation on this!

Reading the snippet though, I wonder if we should instead add a link to drift_flutter sources as an inspiration instead of adding a standalone snippet. IsolateNameServer is a brittle API, and one needs to defend against cases like a hot restart where some isolates are restarted but the dead port is still registered in the isolate server (drift_flutter uses timeouts and pings for that).

But more importantly, IsolateNameServer only exists for Flutter and drift_flutter already does the right thing. So I suppose what the docs should suggest is a stronger focus on using drift_flutter instead of trying to wire up isolates manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publish working example projects that shows how to use the DriftIsolates?

2 participants