Replies: 5 comments 4 replies
-
I can suggest this implementation: source$
.pipe(switchMap((value) => interval(1000).pipe(map(() => value))))
.subscribe(console.log); |
Beta Was this translation helpful? Give feedback.
-
Wow fantastic! How would I integrate this with sampleTime so it uses the last sample? This way it sometimes skip a second. Appears to be the first sequence in the sampleInterval fill in values. Or is it emitting value regardless if sampleTime sends a new value?
|
Beta Was this translation helpful? Give feedback.
-
I'm probably not explaining well! Yes I want to combine it with sampleTime so when sampleTime does not emit a value, because there was nothing to sample in the time period, I can emit the previous sampleTime value. I have this: This gives me the last value received in the last 1000ms. It's a consistent flow as needed for my chart. So I receive:
But if no values are received in the last 1000ms, which does occur sometimes, I get "holes" in the data. Like so:
So I want to fill this gap with the last emitted SampleTime value. Such as:
Makes sens? |
Beta Was this translation helpful? Give feedback.
-
Oh. You mean no need for sampleTime any more...! I tried with
|
Beta Was this translation helpful? Give feedback.
-
@demensky Bingo! Thank you so much. Would be great is sampleTime had a config, similar to ThrottleTime, where we could set a send last value if no new value: true/false, as well as trailing/leading options. I guess many could have this... Thanks again! |
Beta Was this translation helpful? Give feedback.
-
I’m drawing observable stream of values on a chart over time. The chart needs to refreshes on a fix schedule. Say 500ms. I use sampleTime(500) to have a consistent flow but sometimes there is no new data send in that 500ms period and so nothing is emitted and the chart has blanks.
How can I listen to Observable silences and re-emit the value that was received?
The logic would be: use sampleTime(500) values, if no new data in the last 500ms, send the last received value.
thanks
Beta Was this translation helpful? Give feedback.
All reactions