Вопрос

Apologies if this question is deemed inappropriate for SO, but I was wondering if any of you know if there's a significant performance difference between streaming futures via asStream and consuming futures normally via then. Would you expect a general performance difference between the following two operations?

Operation 1

expensiveOperation().asStream().listen((res) {
  doSomething(res);
});

Operation 2

expensiveOperation().then((res) {
  doSomething(res);
});
Это было полезно?

Решение

asStream just allocates a wrapper object and forwards the future's outcome to the stream. All in all you probably won't notice the difference.

If you happen to have a case where you actually measure a slow-down, file a bug on http://dartbug.com. There are still ways to make the wrapper cheaper.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top