isolated 1.0.0 copy "isolated: ^1.0.0" to clipboard
isolated: ^1.0.0 copied to clipboard

This package provides functionality to easily use isolates like automatically setting up the bidirectional communication and request-response functionality.

example/main.dart

import 'dart:convert';

import 'package:isolated/isolated.dart';

const factory = IsolateBundleFactory();

Future<void> main() async {
  final bundle = await factory
      .startNewPingPong<IsolateBundleConfiguration, String, dynamic>(
    deserialize,
    (toCaller) => IsolateBundleConfiguration(toCaller),
  );

  final deserialized = await bundle.pingPong('{"Property": "Hello world"}');
  // ignore:avoid_print
  print(deserialized);
  bundle.cancel();
}

void deserialize(IsolateBundleConfiguration config) {
  config.activateOnCurrentIsolate<PingPongMessage<String>>(
    (message) {
      config.toCaller.send(PingPongMessage<dynamic>(
        message.id,
        jsonDecode(message.value),
      ));
    },
    (cancelMessage) {},
  );
}
1
likes
140
pub points
33%
popularity

Publisher

unverified uploader

This package provides functionality to easily use isolates like automatically setting up the bidirectional communication and request-response functionality.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

uuid

More

Packages that depend on isolated