Situation
I have a system in which one request produces two responses. The request and responses have corresponding observable values:
IObservable<RequestSent> _requests;
IObservable<MainResponseReceived> _mainResponses;
IObservable<SecondResponseReceived> _secondaryResponses;
It is guaranteed that the event RequestSent
occurs earlier than MainResponseReceived
and SecondaryResponseReceived
, but the responses arrive randomly.
What i have
I originally wanted a handler that handles both responses, so I zipped up the observables:
_requests
.SelectMany(async request =>
{
var main = _mainResponses.FirstAsync(m => m.Id == request.Id);
var secondary = _secondaryResponses.FirstAsync(s => s.Id == request.Id);
var zippedResponse = main.Zip(secondary, (m, s) => new MainAndSecondaryResponseReceived {
Request = request,
Main = m,
Secondary = s
});
return await zippedResponse.FirstAsync(); ;
})
.Subscribe(OnMainAndSecondaryResponseReceived);
What I need
Now I need to process also MainResponseReceived
, without waiting for SecondaryResponseRecieved, and it must be guaranteed that OnMainResponseRecieved is completed before OnMainAndSecondaryResponseReceived
called
How to identify two subscriptions, please?
Test case 1:
RequestSent
going onMainResponseReceived
→ OnMainResponseReceived calledSecondaryResponseReceive
d → OnMainAndSecondaryResponseReceived
2:
RequestSent
SecondaryResponseReceived
MainResponseReceived occurs
→ OnMainResponseReceived → OnMainAndSecondaryResponseReceived