cancelable_compute 1.3.0 cancelable_compute: ^1.3.0 copied to clipboard
Flutter based compute operation, that can be canceled with null or with value.
import 'package:cancelable_compute/cancelable_compute.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);
}