Skip to content

Instantly share code, notes, and snippets.

@jcmm33
Created July 4, 2016 16:02
Show Gist options
  • Save jcmm33/af70cb41b8b8e5ea644d5431441097c1 to your computer and use it in GitHub Desktop.
Save jcmm33/af70cb41b8b8e5ea644d5431441097c1 to your computer and use it in GitHub Desktop.
Location Observable Sample
public IObservable<GeoLocation> CurrentLocationObservable(LocationOptions options)
{
IObservable<GeoLocation> observable = null;
if (!_observables.TryGetValue(options,out observable))
{
var coordinates = new Subject<GeoLocation> ();
var geoInstance = new GeoInstance (coordinates, options);
observable= Observable.Create<GeoLocation> ((o) => {
geoInstance.Start ();
var sub = coordinates.
Subscribe (o.OnNext, o.OnError, o.OnCompleted);
var cd = new CompositeDisposable (sub,
Disposable.Create (geoInstance.Stop),
Disposable.Create (() => this.Log ().Information ("Disposed")));
return cd;
}).Replay(1).RefCount ();
_observables [options] = observable;
}
return observable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment