Java2Dart Resource Leak #2

In one of my previous post, I mentioned resource leak handling. I missed the familiar ‘finally’ language keyword.

Dart milestone 3, was released last week, and its cool. There is a new Stream API, and it addressed this issue nicely. The example that was provided:

Future<bool> writeFile(String data, File file) {
   .then((io) => io.writeString(data))
   .then((io) => io.close())
   .then((io) => true)
   .catchError((error) => false);

Catch error is a great solution! No need in finally keyword.