cancelable_compute 2.0.0 copy "cancelable_compute: ^2.0.0" to clipboard
cancelable_compute: ^2.0.0 copied to clipboard

Flutter-based compute operation that can be canceled with either null or a specific value.

example/example.dart

import 'package:cancelable_compute/cancelable_compute.dart';

int fib(int n) {
  if (n < 2) {
    return n;
  }

  return fib(n - 2) + fib(n - 1);
}

Future<int> delayed(int n) async {
  await Future<void>.delayed(Duration(seconds: n ~/ 2));
  return fib(n);
}

Future<void> main() async {
  final operation = compute(delayed, 4);
  Future<void>.delayed(Duration(seconds: 1), operation.cancel);

  final result = await operation.value;
  print(result ?? -1);
}
4
likes
160
pub points
73%
popularity

Publisher

unverified uploader

Flutter-based compute operation that can be canceled with either null or a specific value.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on cancelable_compute