What is this?

Provides simple way to use long-lived Isolate using Commands.

Example (no isolate executor):

final isolate = Isolate.spawn(myMain);
final outPort = await isolate.first;

outPort.send('command-1');

@pragma('vm:entry-point')
void myMain(SendPort outPort) async {
  final inPort = ReceivePort();

  outPort.send(inPort.sendPort);
  
  MyResult command1() {
    return MyResult();  
  }
  
  await for (final event in inPort) {
    switch(event) {
      case 'command-1':
        return outPort.send(command1());
    }
  }
}

Example (IsolateExecutor)

final executor = await IsolatedExecutor.stateless();

/// Run for callbacks.
executor.run(command1);

/// Execute for commands.
executor.execute(Command1(AData()));

MyResult command1() {
  return MyResult();
}

/// Extend StatelessCommand to automatically generate unique [id] for every command.
class Command1 extends StatelessCommand<int> {
    Command1(this.a);
    
    final AData a;
    
    int execute() => a.nothingIsTrueEverythingIsPermitted ? 42 : -1;
}

As you can see u can easily focus on actual actions.

Libraries

isolated_executor