4 ms·
I believe that the distinguishing property is not what the event/data/codata is, rather how you are accessing it and when you process it. In a "push" model you
by isoos 9y ago
I believe that the distinguishing property is not what the event/data/codata is, rather how you are accessing it and when you process it.
In a "push" model you provide a callback that will receive events and it has no way of influencing their frequency or timing. There is no mandatory buffering here.
In the "pull" model, you have a handle, that you can call to receive the next event, which is essentially an iteration over async events. It is up to you to decide the frequency or the timing, and it is up to the backing library to buffer events if needed to be.
I'm linking to the Dart API pages here, but the same concept applies to every language/library out there. Stream.listen [0] is straightforward and similar to many other libs out there. The interesting part is that Dart has a StreamIterator[1], which allows you to "pull" events form the stream at your own pace.
[0] https://api.dartlang.org/stable/1.24.3/dart-async/Stream-class.html#listen https://api.dartlang.org/stable/1.24.3/dart-async/Stream-cla...
[1] https://api.dartlang.org/stable/1.24.3/dart-async/StreamIterator-class.html https://api.dartlang.org/stable/1.24.3/dart-async/StreamIter...
It is also easy to use Stream Iterator to loop over the values unconditionally:
Stream<Event> stream = whatever();
var iter = new StreamIterator<Event>(stream);
while (await iter.moveNext()) {
// process the iter.current value at whatever pace you'd like
}
- naasking 9y ago> I believe that the distinguishing property is not what the event/data/codata is, rather how you are accessing it and when you process it. But this is exactly one of the important distinctions between data and codata. If your language supported first-class codata, you wouldn't need to encode push evaluation via a stream data type. Codata already has the required push-like semantics, and your language's evaluation model would handle the necessary plumbing for you.