Sdk: method for getting a Stream's current value

Created on 10 Mar 2014  路  2Comments  路  Source: dart-lang/sdk

_This issue was originally filed by bslesinsk...@gmail.com_


It would be convenient to have a way to get a Stream's most recently added value without either removing it or blocking. For example, suppose you want to see the current value of a stream whenever rendering a frame:

window.animationFrame.listen((_) {
  var currentValue = streamOfChanges.sample;
  // render the current value
});

This would allow us to use streams in a way similar to Elm's sampleOn function [1].

Workaround: use listen() to set a variable.

[1] http://elm-lang.org/learn/What-is-FRP.elm

area-library closed-not-planned library-async type-enhancement

All 2 comments

If anything, it should be a getter on the subscription. Each subscription on a broadcast stream can have a different "most recent" event value.

I don't think we are going to do this, because the workaround is so simple, it would be unnecessary overhead if it isn't used, it might leak memory if events are large, and some streams may want to reuse parts of the event after it has been fired (like I/O buffers).


_Removed Type-Defect label._
_Added Type-Enhancement, Library-Async, Area-Library, Triaged labels._

After thinking about it more, we still don't want this as a feature of all streams.


_Added NotPlanned label._

Was this page helpful?
0 / 5 - 0 ratings