conduit_isolate_exec 5.1.3 copy "conduit_isolate_exec: ^5.1.3" to clipboard
conduit_isolate_exec: ^5.1.3 copied to clipboard

This library contains types that allow for executing code in a spawned isolate, perhaps with additional imports.

conduit_isolate_exec #

This library contains types that allow for executing code in a spawned isolate, perhaps with additional imports.

Subclass Executable and override its execute method. Invoke IsolateExecutor.executeWithType, passing in that subclass. The code in execute will run in another isolate. Any value it returns will be returned by IsolateExecutor.executeWithType.

A returned value must be a primitive type (anything that is encodable as JSON). You may pass parameters to the other isolate by providing a message map.

Example:

class Echo extends Executable {
  Echo(Map<String, dynamic> message)
      : echoMessage = message['echo'],
        super(message);

  final String echoMessage;

  @override
  Future<dynamic> execute() async {
    return echoMessage;
  }
}

Future main() async {
    final result = await IsolateExecutor.executeWithType(Echo, message: {'echo': 'hello'});
    assert(result == 'hello');
}
2
likes
120
points
2.19k
downloads

Publisher

verified publishertheconduit.dev

Weekly Downloads

This library contains types that allow for executing code in a spawned isolate, perhaps with additional imports.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-2-Clause (license)

Dependencies

analyzer, glob, path

More

Packages that depend on conduit_isolate_exec