Exemplo n.º 1
0
 public Task Subscribe(object owner, Func <Task> callback)
 {
     lock (_mutex)
     {
         _handlers += (owner, callback);
     }
     return(callback());
 }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 public AsyncEvent()
 {
     _handlers = new ContextMulticastFuncTask();
 }