You could join by coincidence.
from request in requests // 1
join response in responses // 2
on responses.Where(response => response.Id == request.Id) // 1,3
equals Observable.Empty<Unit>() // 2
where request.Id == response.Id // 4
select response.Time - request.Time // 5
Think of it like this:
- Create a window for each request.
- Project every response into every request window.
- When a response matches a request, close that request window.
- For each request, ignore all responses that do not match.
- Project the time difference for the response that does match.
Update:
Request windows are opened by from
and closed by on
.
Response windows are opened by join
and closed by equals
. The response duration specified by equals
is Empty
, thus responses aren't actually windows - they are treated as point events and simply projected once into whatever request windows are currently open.
#3 requires a Where
operator because it defines the duration of each request; i.e., it indicates when a request window closes, which is when a response with a matching ID arrives.
#4 is required because of #3. Think about it - we're cross-joining every response with every request window that's currently open. Request windows only close when a matching response arrives. That means every response that doesn't match is paired with every request, but you only care about the last response - the one that matches.