I am developing flutter application (at the time just for Android, but with iOS support planned for later). Application operates in two ways:
- Flutter UI with most of the business logic (Foreground isolate, started with main method) (FG)
- Some automatic tasks performed on background using android WorkManager (Which uses Flutter Background Isolate) (BG)
- Both isolates are using Database
Since we need to use Database in "thread-safe" manner we are trying to use Moor database framework, with moor_ffi interface to talk to Sqlite server.
Moor claims to achieve it's "thread-safety" by spawning the third Isolate (MoorIsolate). This isolate is the only one that talks to the database. Queries executed in BG and FG are sent to this isolate using SendPort/ReceivePort, executed and returned to caller Isolate.
However all Moor example suggest spawning MoorIsolate from FG isolate. Which draws my attention to following concerns.
- What happens to the MoorIsolate if the FG Isolate "dies"
- If user exits by pressing the back button on last screen in Navigotor?
- If APP is not visible for some time and the OS decides to free up it's memory.
- If users "force-kills" app in settings (this should ideally be only case where MoorIsolate dies)
- In BG isolate we are using IsolateNameServer to construct MoorIsolate. Is there any way we can detect if Isolate is still running?
I am developing flutter application (at the time just for Android, but with iOS support planned for later). Application operates in two ways:
Since we need to use Database in "thread-safe" manner we are trying to use Moor database framework, with moor_ffi interface to talk to Sqlite server.
Moor claims to achieve it's "thread-safety" by spawning the third Isolate (MoorIsolate). This isolate is the only one that talks to the database. Queries executed in BG and FG are sent to this isolate using SendPort/ReceivePort, executed and returned to caller Isolate.
However all Moor example suggest spawning MoorIsolate from FG isolate. Which draws my attention to following concerns.