integral_isolates 0.3.0+1 copy "integral_isolates: ^0.3.0+1" to clipboard
integral_isolates: ^0.3.0+1 copied to clipboard

The power of Flutter's compute function, but using a long lived isolate.

Easy to use isolates for Dart and Flutter.

Usage #

Almost as easy to use as compute, but using a long lived isolate. For example:

void main() async {
  final isolated = Isolated();
  final isolate = isolated.isolate;
  print(await isolate(_isPrime, 7));
  print(await isolate(_isPrime, 42));
  isolated.dispose();
}

bool _isPrime(int value) {
  if (value == 1) {
    return false;
  }
  for (int i = 2; i < value; ++i) {
    if (value % i == 0) {
      return false;
    }
  }
  return true;
}

Remember to always dispose once you are done using the isolate to clean up and close the isolate.

isolated.dispose();

Different backpressure strategies are also supported by just sending in the desired strategy:

Isolated(backpressureStrategy: DiscardNewBackPressureStrategy());

Currently supported strategies can be found in the documentation.

Additional information #

The API of this package is not final, and is subject to change.

Are you using hooks? #

Try the use_isolate package that controls the lifecycle of the isolate, so you don't have to.

29
likes
0
pub points
81%
popularity

Publisher

verified publisherlohnn.se

The power of Flutter's compute function, but using a long lived isolate.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

async, meta

More

Packages that depend on integral_isolates