Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What difference between add and sink.add?

Tags:

dart

I can't figure out what difference between .add and .sink.add?

Example:

StreamController myStreamController = StreamController();
stream = Stream<int>.periodic(Duration(seconds: 1), (t) => t + 1).take(3);

When I should do:

myStreamController.sink.add(myStreamController);

and when:

myStreamController.add(myStreamController);
like image 244
Dmitry Bubnenkov Avatar asked Sep 15 '25 13:09

Dmitry Bubnenkov


1 Answers

It does the same. The purpose of the sink property are to provide a restricted interface for you streamcontroller:

Returns a view of this object that only exposes the StreamSink interface.

https://api.dart.dev/stable/2.5.0/dart-async/StreamController/sink.html

like image 150
julemand101 Avatar answered Sep 17 '25 04:09

julemand101