d-markey / squadron

Multithreading and worker thread pool for Dart / Flutter, to offload CPU-bound and heavy I/O tasks to Isolate or Web Worker threads.
https://pub.dev/packages/squadron
MIT License
79 stars 0 forks source link

Running native plugins in squadron isolates #33

Closed dallas1287 closed 8 months ago

dallas1287 commented 8 months ago

So I get this error message when trying to run a native decoder plugin with a squadron setup. Bad state: The BackgroundIsolateBinaryMessenger.instance value is invalid until BackgroundIsolateBinaryMessenger.ensureInitialized is executed. I've been down the rabbit hole a bit with this and I've found this: https://github.com/flutter/flutter/issues/119207 which is about not being able to do event streaming from platform back to dart on an isolate. That I have a workaround for so, while disappointing, I can get past. And then there's this guy https://github.com/lamnhan066/isolate_manager/issues/5 which is the same error message I get although using a different package. But they suggest passing in that rootInstanceToken to your compute isolates. I tried what I would think would be analogous in squadron but I'm still getting the error. Do you have any pro tips or breadcrumbs that can get this working for me. I'd love to not have to do my decoder threads on the main isolate.

d-markey commented 8 months ago

I wish it worked indeed, but it seems you're already pretty well documented. Can't add anything to what you've found so far, so it seems this is not possible at the moment unfortunately. Please track those two issues and when things look brighter, try again and reopen an issue if Squadron needs any adjustment. Maybe e.g. Squadron will have to ensure the messenger is initialized.