I have a stream with a transformer that fuses the UTF8.decoder to the LineSplitter. It works great but never calls the function specified in the onDone parameter.
import 'dart:async';
import 'dart:io';
import 'dart:convert';
void main(List<String> arguments) {
Stream<List<int>> stream = new File("input.txt").openRead();
stream.transform(UTF8.decoder.fuse(const LineSplitter()))
.listen((line) {
stdout.writeln(line);
}, onDone: () {
stdout.write("done");
}).asFuture().catchError((_) => print(_));
}
Any ideas why it is never getting called?
The problem is that you used the asFuture() method.
If you don't use that, onDone will be called properly when EOF is reached; otherwise, you should put a .then((_) => print('done')) after the Future return value of asFuture() for the same effect.
The resulting code should look like this:
(stream
.transform(utf8.decoder)
.transform(LineSplitter())
.listen((line) => print(line))
.asFuture())
.then((_) => print("done"))
.catchError((err) => stderr.writeln(err));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With