public Task Subscribe(object owner, Func <Task> callback) { lock (_mutex) { _handlers += (owner, callback); } return(callback()); }
public AsyncEvent(T initValue = default(T)) { _handlers = new ContextMulticastFuncTask <T>(); // by default, on subscribe we notify with the latest value _onSubscribe = async(cb) => { await cb(LatestValue); }; LatestValue = initValue; }
public Task Unsubscribe(object owner, Func <Task> callback = null) { if (callback == null) { lock (_mutex) { _handlers -= owner; } } else { lock (_mutex) { _handlers -= (owner, callback); } } return(Tasks.Empty); }
public AsyncEvent() { _handlers = new ContextMulticastFuncTask(); }