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

outdated

Spawn an isolate, run callback on that isolate, passing it message, and return the value returned by callback or canceled by user.

example/example.dart

// import 'package:cancelable_compute/cancelable_compute.dart';

import 'package:cancelable_compute/src/web.dart';

Future<void> main() async {
  final operation = compute(delayed, 5);
  Future<void>.delayed(Duration(seconds: 1), operation.cancel);
  final result = await operation.value;
  print(result ?? -1);
}

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

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

Future<int> delayed(int seconds) {
  return Future.delayed(Duration(seconds: seconds), () => seconds);
}
4
likes
0
points
158
downloads

Publisher

unverified uploader

Weekly Downloads

Spawn an isolate, run callback on that isolate, passing it message, and return the value returned by callback or canceled by user.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on cancelable_compute