somehow_i_manage 1.1.4 somehow_i_manage: ^1.1.4 copied to clipboard
A dart package making working with Isolates easier and manageable. It supports interprocess communication
THis package helps it easier to work with threads i.e. Isolates to make task distribuion easier
Features #
- Pausing work
- Inter Isolate communication
Getting started #
Add the package to your project by using this command
dart pub add somehow_i_manage
Usage #
To use this package create a worker like so
IWorker worker = IWorker.create(name: "name");
You can add callbacks for receiving messages from isolates like below
IWorker iWorker = await IWorker.create("create-test", onReceiveMessage: (message, _) {
print("message received");
expect(message.tag, "Selfie");
});
IWorker iWorker2 = await IWorker.create("create-test-2", onReceiveMessage: (message, _) {
print("message received 2");
expect(message.tag, "Selfie");
});
iWorker.sendMessage(sendPort: iWorker2.messageSendPort, tag: "Selfie");
await Future.delayed(Duration(seconds: 1));
print("Sent message");
Do not forget to dispose the worker when done using it
IWorker iWorker = await IWorker.create("create-test");
//computation here
iWorker.dispose();
This makes it easy to spawn Isolates and keep them alive for future jobs
Additional information #
Contributions are welcome