如果我在DART中有Stream
,我可以同时使用listen
和forEach
,但我不明白其中的区别.
例如,考虑这个代码:
final process = await Process.start('pub', ['serve']);
process.stdout.map((l) => UTF8.decode(l)).forEach(print);
我也可以写下:
process.stdout.map((l) => UTF8.decode(l)).listen(print);
有什么区别吗?