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) {
 return file.open(FileMode.WRITE)
   .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.
 

 

 

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com