예제 #1
0
 public AsyncOperationResult DispatchSynchronously(object?arg)
 {
     if (Interlocked.Exchange(ref _awaitsResolution, 0) == 1)
     {
         if (_task == null)
         {
             try
             {
                 return(AsyncOperationResult.Success(_action(arg).Result));
             }
             catch (Exception ex)
             {
                 return(AsyncOperationResult.Failure(ex));
             }
         }
         else
         {
             return(_task.Result);
         }
     }
     else
     {
         throw new NotImplementedException();
     }
 }
예제 #2
0
        public void Dispatch(object?arg, Action <AsyncOperationResult> callback)
        {
            var threadStart = new ThreadStart(() =>
            {
                try
                {
                    var result = AsyncOperationResult.Success(_action(arg));
                    if (Interlocked.Exchange(ref _awaitsResolution, 0) == 1)
                    {
                        _result = result;
                        callback(result);
                    }
                }
                catch (Exception ex)
                {
                    if (Interlocked.Exchange(ref _awaitsResolution, 0) == 1)
                    {
                        _result = AsyncOperationResult.Failure(ex);
                        callback(_result);
                    }
                }
            });

            _thread = new Thread(threadStart);
            _thread.Start();
        }
예제 #3
0
 internal void Accept(object?result)
 {
     State  = AsyncOperationState.Completed;
     Result = AsyncOperationResult.Success(result);
     while (_continuations.TryDequeue(out var continuation))
     {
         continuation.Dispatch(Result.Value);
     }
 }
예제 #4
0
 public void Dispatch(object?arg, Action <AsyncOperationResult> callback)
 {
     if (_operation == null)
     {
         _operation = _action(arg);
     }
     _operation.Catch <Exception>(ex => callback(AsyncOperationResult.Failure(ex)));
     _operation.ThenWait(() => callback(AsyncOperationResult.Success()));            //operation.ThenWait(() => callback(null));
 }
예제 #5
0
 public AsyncOperationResult DispatchSynchronously(object?arg)
 {
     try
     {
         return(AsyncOperationResult.Success(_action(arg)));
     }
     catch (Exception ex)
     {
         return(AsyncOperationResult.Failure(ex));
     }
 }
예제 #6
0
 public void Dispatch(object?arg, Action <AsyncOperationResult> callback)
 {
     try
     {
         callback(AsyncOperationResult.Success(_action(arg)));
     }
     catch (Exception ex)
     {
         callback(AsyncOperationResult.Failure(ex));
     }
 }
예제 #7
0
 internal virtual AsyncOperationResult Handle(Exception exception)
 {
     if (_catchHandlers.TryHandle(exception))
     {
         return(AsyncOperationResult.Success());
     }
     else
     {
         return(AsyncOperationResult.Failure(exception));
     }
 }
예제 #8
0
        internal override AsyncOperationResult Handle(Exception exception)
        {
            TPass resultValue;

            if (_catchHandlers.TryHandle(exception, out resultValue))
            {
                return(AsyncOperationResult.Success(resultValue));
            }
            else
            {
                return(AsyncOperationResult.Failure(exception));
            }
        }
예제 #9
0
 public AsyncOperationResult DispatchSynchronously(object?arg)
 {
     if (_operation == null)
     {
         _operation = _action(arg);
     }
     _operation.Dispatch(arg);
     try
     {
         _operation.Wait();
         return(AsyncOperationResult.Success());
     }
     catch (Exception ex)
     {
         return(AsyncOperationResult.Failure(ex));
     }
 }
예제 #10
0
 public void Dispatch(object?arg, Action <AsyncOperationResult> callback)
 {
     _actionHandle = new AsyncEventArgs(() =>
     {
         try
         {
             _result = AsyncOperationResult.Success(_action(arg));
             callback(_result);
         }
         catch (Exception ex)
         {
             _result = AsyncOperationResult.Failure(ex);
             callback(_result);
         }
     });
     Async.Dispatch(_actionHandle);
 }
예제 #11
0
 public AsyncOperationResult DispatchSynchronously(object?arg)
 {
     if (_actionHandle.Resolve())
     {
         try
         {
             return(_result = AsyncOperationResult.Success(_action(arg)));
         }
         catch (Exception ex)
         {
             return(_result = AsyncOperationResult.Failure(ex));
         }
     }
     else
     {
         return(_result !);
     }
 }
예제 #12
0
 public AsyncOperationResult DispatchSynchronously(object?arg)
 {
     if (Interlocked.Exchange(ref _awaitsResolution, 0) == 1)
     {
         try
         {
             return(_result = AsyncOperationResult.Success(_action(arg)));
         }
         catch (Exception ex)
         {
             return(_result = AsyncOperationResult.Failure(ex));
         }
     }
     else
     {
         return(_result !);
     }
 }
예제 #13
0
        public void Dispatch(object?arg, Action <AsyncOperationResult> callback)
        {
            _task = Task.Run(async() => {
                try
                {
                    return(AsyncOperationResult.Success(await _action(arg)));
                }
                catch (Exception ex)
                {
                    return(AsyncOperationResult.Failure(ex));
                }
            }, _cancellation.Token);

            _task.ContinueWith(task => {
                if (Interlocked.Exchange(ref _awaitsResolution, 0) == 1)
                {
                    callback(task.Result);
                }
            });
        }
예제 #14
0
 public AsyncOperation(TPass value)
     : base(AsyncOperationResult.Success(value))
 {
 }