Skip to content

Instantly share code, notes, and snippets.

@teo-mateo
Last active December 31, 2015 18:49
Show Gist options
  • Select an option

  • Save teo-mateo/8029946 to your computer and use it in GitHub Desktop.

Select an option

Save teo-mateo/8029946 to your computer and use it in GitHub Desktop.
public class LocationSubscriber : IObserver<Location>
{
private IDisposable unsubscriber;
private string instName;
public LocationSubscriber(string name)
{
this.instName = name;
}
public string Name { get { return this.instName; } }
public virtual void Subscribe(IObservable<Location> provider)
{
if (provider != null)
unsubscriber = provider.Subscribe(this);
}
public virtual void OnCompleted()
{
Console.WriteLine("The Location Tracker has completed transmitting datat to {0}", this.Name);
this.Unsubscribe();
}
public virtual void OnError(Exception ex)
{
Console.WriteLine("{0} location cannot be determined.", this.Name);
}
public virtual void OnNext(Location value)
{
Console.WriteLine("{2}: the current location is {0}, {1}", value.Latitude, value.Longitude, this.Name);
}
public virtual void Unsubscribe()
{
unsubscriber.Dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment