Skip to content

Flutter, Moor and WorkManager #637

Description

@MartinHlavna

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.

  1. 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)
  1. In BG isolate we are using IsolateNameServer to construct MoorIsolate. Is there any way we can detect if Isolate is still running?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions