Reputation: 541
In my Flutter app, we have the app's main isolate as well as another isolate created by the Flutter workmanager
plugin - so I can't share a SendPort instance to the new isolate. Since the background workers can be run at (almost) any time, the order in which the main and the background isolate is spawned is not defined.
In our main app and in the background worker we do non-thread-safe operations like refreshing the authentication token, so we need to make sure one isolate does the work at a time.
Is there something like a named mutex which can share a locking-mechanism across isolates without any references except for constants like names (as String or similar)?
I've already tried to make use of the IsolateNameServer
, but there you can only create a uni-directional communication and I don't know how that could help us either.
Upvotes: 0
Views: 82
Reputation: 44066
You might look into https://pub.dev/packages/shared_map to coordinate updates.
Upvotes: 0