import 'dart:io'; import 'dart:async'; import 'dart:convert'; Future<String> _sendRequest() async { var http = new HttpClient(); return http .postUrl(Uri.parse("https://www.google.com/404")) .then((HttpClientRequest request) => request.close()) .then((HttpClientResponse response) { return response.transform(UTF8.decoder).join(""); }); } main(List<String> args) async { print("starting..."); print(await _sendRequest()); print("finished"); }
I think you need to close the HttpClient as well.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Since your function body is defined as async, you can use try-finally:
try {
var request = await http.postUrl(...);
var response = await request.close();
return response.transform(...).join('');
} finally {
http.close();
}
No, because Dart doesn't have destructors like C# or C++ or Python, so we can't do cleanup or RIIA (resource allocation is initialization) the same way.
No, because Dart doesn't have destructors like C# or C++ or Python, so we can't do cleanup or RIIA (resource allocation is initialization) the same way.