Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell if an HttpResponse is already closed?

Tags:

dart

dart-io

Using Dart's dart:io library, how can I tell if an HttpResponse is already closed?

I couldn't find a hint in the API docs: http://api.dartlang.org/docs/releases/latest/dart_io/HttpResponse.html

like image 219
Seth Ladd Avatar asked Nov 02 '22 19:11

Seth Ladd


1 Answers

Stab in the dark here, but would connectionInfo being null mean that the HttpResponse has finished?

Otherwise, I guess you could set a "closed" bool variable from the Future returned by done, and test whether it's set before processing the response?

HttpResponse response = ...;
bool closed = false;
response.done.then((_) => closed = true);

if (!closed) {
  ...
}

But I'm not sure whether you could ever do this early enough, would depend on the scenario.

like image 145
ianmjones Avatar answered Nov 15 '22 08:11

ianmjones