AndrewSB AndrewSB - 4 months ago 33
Swift Question

RxSwift flatMap latest one time without disposing

Had a quick question: I have an

, where

class Session {
var rx_serverRequestable: Driver<SessionRequestable>

which emits a .next event every time the session has all the information it needs to be passed on to the backend and I want to be able to
on the array of sessions, and do something like:

let sessions: Variable<[Session]>
.flatMapLatest { sessions in { $0. rx_serverRequestable } }
.flatMap { $0.requestFromServer() }

but I only want to request each session once. There are two ways I see that failing with my current implementation:
1. flatMapLatest gets a new array of sessions, potentially disposing a request from server thats still in progress
2. rx_serverRequestable gets called each time the session has all the information required to be loaded from server, so it will get called multiple times, each time the session loads in any new information. I only want the session to be requested the first time, should I be using something like

any pointers on solving the two issues, or switching up my approach?


This can be solved using the zip operator