Synchronously Waiting for a Future or Stream to Complete in Dart

I play with a tiny web server, and I implement one version using the async package, and one synchronous version executing each request in a separate isolate. I would like to just transfer the file stream to HttpResponse , but I cannot do it synchronously. And I can’t find a way to not wait for either Stream or a Future synchronously. Now I use RandomAccessFile , which works, but it gets messy.

One solution would be to run a periodic timer to check if the future is complete (by setting a logical or similar), but this is definitely not what I want to use.

Is there a way to wait in sync for Future and a Stream ? If not, why?

+4
source share
1 answer

AFAIK there is no way to wait synchronously for the Future or the Stream. What for? Because they are fairly asynchronous, and as you discover, the APIs are designed with asynchronous behavior in mind.

There are several Future, Future.value() and Future.sync() that execute immediately, but I don't think this is probably what you mean.

+1
source

Source: https://habr.com/ru/post/1493395/


All Articles