I have two observables: LoadLocal and LoadServer. LoadLocal loads and returns an item from a local source, and LoadServer retrieves it from the server. I want to combine them into another observable: Load. I want Load to get an element from LoadLocal, and if it is null, I want to return an element from LoadServer. Any ideas how to do this?
thank
Details of the real scenario:
Func<Guid, IObservable<IAsset>> loadLocal = Observable.ToAsync<Guid, IAsset>(id => GetLocalAsset(id));
var svcClient = new ServiceClient<IDataService>();
var svc = Observable.FromAsyncPattern<Request, Response>(svcClient.BeginInvoke, svcClient.EndInvoke);
var loadServer = id => from response in svc(new Request(id)) select response.Asset;
var load = ???
The following almost gives me the desired result, however both loadLocal (id) and loadServer (id) start up. If loadLocal (id) returns an element, I do not want to run loadServer (id).
var load = id => loadLocal(id).Zip(loadServer(id), (local, server) => local ?? server);
Pking source
share