title: Flutter, Moor and WorkManager
body: <p>I am developing a flutter application (at the time just for Android, but with iOS support planned for later). The application operates in two ways:</p>
  
  <ul>
  <li>Flutter UI with most of the business logic (Foreground isolate, started with the main method) (FG)</li>
  <li>Some automatic tasks performed on the background using android WorkManager (Which uses Flutter Background Isolate) (BG)</li>
  <li>Both isolates are using Database</li>
  </ul>
  
  <p>Since we need to use Database in the "thread-safe" manner we are trying to use the Moor database framework, with the moor_ffi interface to talk to SQLite server.</p>
  
  <p>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.</p>
  
  <p>However, all Moor examples suggest spawning MoorIsolate from FG isolate. Which draws my attention to the following concerns.</p>
  
  <ol>
  <li><p>What happens to the MoorIsolate if the FG Isolate "dies"</p>
  
  <p>1.1 If the user exits by pressing the back button on the last screen in Navigator?</p>
  
  <p>1.2 If the APP is not visible for some time and the OS decides to free up its memory.</p>
  
  <p>1.3 If users "force-kills" app in settings (this should ideally be the only case where MoorIsolate   dies)</p></li>
  <li><p>In BG isolate  we are using IsolateNameServer to construct MoorIsolate. Is there any way we can detect if Isolate is still running? </p></li>
  </ol>