Let's say I have two observables, observableA and observableB.
There are 3 cases for how these two observables can be triggered:
- Only observableA gets triggered.
- Only observableB gets triggered.
- ObservableA gets triggered first, followed by observableB after a 1-second delay.
How can I handle these two observables so that the callback function won't execute twice?
expecting: the callback function won't execute twice
So what's not said is that it's ok to wait to see if B is going to trigger after an A. The only way to solve this is have a window in which after A triggers you wait X seconds then trigger to continue with A, or you receive a B and go with that logic.
bufferTimecan serve as this. First we merge A and B together then we buffer those 2 observables up.You have to handle the case where neither A nor B fire which will be an empty array, and just ignore it.