From 5c88203d06f2b9f0a2fee6d18c91ad16dfaac7ae Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sun, 27 Jun 2021 16:55:40 +0200 Subject: [PATCH] Docs: Add warning about initializatin and isolates --- docs/pages/docs/Advanced Features/isolates.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/pages/docs/Advanced Features/isolates.md b/docs/pages/docs/Advanced Features/isolates.md index 926188c7..2c56245f 100644 --- a/docs/pages/docs/Advanced Features/isolates.md +++ b/docs/pages/docs/Advanced Features/isolates.md @@ -147,6 +147,19 @@ DatabaseConnection _createMoorIsolateAndConnect() { } ``` +{% block "blocks/alert" title="Initializations and background isolates" color="warning" %} +As the name implies, Dart isolates don't share memory. This means that global variables +and values accessible in one isolate may not be visible in a background isolate. + +For instance, if you're using `open.overrideFor` from `package:sqlite3`, you need to do that +on the isolate where you're actually opening the database! +With a background isolate as shown here, the right place to call `open.overrideFor` is in the +`_startBackground` function, before you're using `MoorIsolate.inCurrent`. +Other global fields that you might be relying on when constructing the database (service +locators like `get_it` come to mind) may also need to be initialized seperately on the background +isolate. +{% endblock %} + ### Shutting down the isolate Since multiple `DatabaseConnection`s can exist to a specific `MoorIsolate`, simply calling