Your code probably wouldn't work as expected as your algorythm may block the returning of the completer. Try it this way:
Future<int> timeconsumingFunctionReturningFuture(int i) {
var completer = new Completer();
if (i==0) {
completer.completeError(88);
} else {
Timer.run(() {
int rc;
// Line9: rc = timeconsuming algorithm, to calculate rc
completer.complete(rc);
});
}
return completer.future;
}
This way your timeconsuming algorithm runs asynchronously and the future is returned immediately.
I have not tried it myself but this shorter version should also work (without creating a completer)
return new Future.delayed(Duration.ZERO, () {
// timeconsuming algorithm
});