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

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

pub package

cancelable-compute.dart #

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

Usage #

A simple usage example:

import 'package:cancelable_compute/cancelable_compute.dart';

Future<void> main() async {
  var operation = compute(fib, 255);

  void onTap() {
    operation.cancel(-1);
  }

  final result = await operation.value;
  print(result);
}

Note for Web #

Canceling doesn't stop the running future. The future will continue to execute, but the value future will resolve immediately with null (or the provided data if cancel was called with data) instead of waiting for the computation to finish.

import 'package:cancelable_compute/cancelable_compute.dart';

Future<void> main() async {
  var operation = compute((_) async {
    await Future<void>.delayed(Duration(seconds: 5)); // Long running task
    return 'Completed';
  }, 0);

  Future<void>.delayed(Duration(seconds: 1), () {
    operation.cancel('Canceled');
  });

  final result = await operation.value;
  print(result); // Will print "Canceled" after 1 second on web.
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

License #

MIT

4
likes
160
points
209
downloads

Publisher

unverified uploader

Weekly Downloads

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