Im trying to combine 3 streams
- accelerometer stream from sensors_plus
- orientation stream from flutter_rotation_sensor
- location stream from geolocator
Im using CombineLatestStream from rxdart to combine these streams and what I understand is that when either of the 3 emit a new value, the combined stream will emit a new value.
This was fine but I then added throttleTime() to the stream, now what I understand is that the first value emitted by the combined stream during the window will be taken and everything after that will be ignored until the next window.
Im confused about the behaviour when: say stream 1, stream 2, stream 3 emit [A1, B1, C1] respectively now this is emitted by the combined stream and the throttling begins, during this time stream 1 being faster emits again and so the values are [A2, B1, C1]. The process repeats and stream 1 happens to emit first again(A3), will the latest values of stream 2 and stream 3 be considered or will the same stale values(B1, C1) keep getting emitted if stream 1 happens to be faster to emit in each throttling window?
CombineLatestStream.list([
accelerometerEventStream(
samplingPeriod: SensorInterval.fastestInterval), // Stream 0
frs.RotationSensor.orientationStream, // Stream 1
getLocationUpdates(), // Stream 2
])
.throttleTime(const Duration(milliseconds: 18))
.listen((data) {
// data[i] corresponds to the ith stream
final accEvent = data[0] as AccelerometerEvent;
final frsEvent = data[1] as frs.OrientationEvent;
final locEvent = data[2] as Position;
final now = DateTime.now();
// code to necessary perform operations on the data
});
I expect the latest data from each of the streams to be emitted every 20ms. I couldn't find a clear explaination of this behaviour, any help or alternative approach will be appreciated, thank you.