public bool Unsubscribe(IIOClientChannel channel) { IOEventSubscription subscription; if (!eventSubscriptions.TryRemove(channel, out subscription)) { return(false); } OnUnsubscribed(new IOEventSubscriberEventArgs(subscription)); subscription.Dispose(); return(true); }
private IDisposable Subscribe(int id, IObservable <object> observable, IIOClientChannel channel) { return(observable.ObserveOn(TaskPoolScheduler.Default).Subscribe(value => { try { channel.Update(id, value); } catch { Unsubscribe(channel); } })); }
public void Subscribe(IIOClientChannel channel, string name) { var subscription = new IOEventSubscription(name); foreach (var channelSubject in channelSubjects) { int id = channelSubject.Key; subscription.Handles.Add(Subscribe(id, channelSubject.Value, channel)); } eventSubscriptions.AddOrUpdate(channel, subscription, (c, s) => { s.Dispose(); return(subscription); }); OnSubscribed(new IOEventSubscriberEventArgs(subscription)); }