Running isolate easily.
Give more power to your app with multicore processing.
import 'dart:io';
void main() {
// run core dedicated isolates.
Parallel.initialize(
numberOfIsolates: Platform.numberOfProcessors -1, // minus one used for allocating to main isolate.
maxConcurrentPerIsolate: 100, // limit to 100 execution per isolate
onInitialization: () {
// register your dependency injection
// for example using GetIt.I.register...
},
);
runApp(MyApp());
}
Execute action in isolate.
final result = await Parallel.run((){
// do your heavy task here.
});
Execute action in main isolate from worker isolate.
final result = await Parallel.run((){
final data = await Parallel.runInMain((){
// get your main data
});
print(data);
});
WARNING: Since isolates are not sharing memory each other, you have to make sure the data that passed between isolates are not mutable.