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(); } }
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(); }
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)); }
internal void Accept(object?result) { State = AsyncOperationState.Completed; Result = AsyncOperationResult.Success(result); while (_continuations.TryDequeue(out var continuation)) { continuation.Dispatch(Result.Value); } }
internal virtual AsyncOperationResult Handle(Exception exception) { if (_catchHandlers.TryHandle(exception)) { return(AsyncOperationResult.Success()); } else { return(AsyncOperationResult.Failure(exception)); } }
public AsyncOperationResult DispatchSynchronously(object?arg) { try { return(AsyncOperationResult.Success(_action(arg))); } catch (Exception ex) { return(AsyncOperationResult.Failure(ex)); } }
public void Dispatch(object?arg, Action <AsyncOperationResult> callback) { try { callback(AsyncOperationResult.Success(_action(arg))); } catch (Exception ex) { callback(AsyncOperationResult.Failure(ex)); } }
private void _complete(AsyncOperationResult result) { if (result.IsSuccessful) { Accept(result.Value); } else { Reject(result.Error !); } }
internal override AsyncOperationResult Handle(Exception exception) { TPass resultValue; if (_catchHandlers.TryHandle(exception, out resultValue)) { return(AsyncOperationResult.Success(resultValue)); } else { return(AsyncOperationResult.Failure(exception)); } }
protected AsyncOperationResult _Wait() { switch (State) { case AsyncOperationState.Deferred: throw new InvalidOperationException("Cannot wait for an AsyncOperation that is Deferred"); case AsyncOperationState.Aborted: return(AsyncOperationResult.Failure(new InvalidOperationException("Cannot wait for an operation that has been aborted."))); case AsyncOperationState.Failed: return(AsyncOperationResult.Failure(new AsyncException(Result !.Error !))); case AsyncOperationState.Initial: if (_preceedingOperation == null) { return(Operator !.DispatchSynchronously(null)); } var pass = _preceedingOperation._Wait(); if (!pass.IsSuccessful) { pass = Handle(pass.Error !); } if (pass.IsSuccessful) { return(Operator !.DispatchSynchronously(pass.Value)); } else { return(pass); } case AsyncOperationState.Dispatched: if (_preceedingOperation != null) { return(Operator !.DispatchSynchronously(_preceedingOperation.Result)); } else { return(Operator !.DispatchSynchronously(null)); } case AsyncOperationState.Completed: return(Result !); default: throw new NotSupportedException("Unsupported AsyncOperationState '" + Enum.GetName(typeof(AsyncOperationState), State) + "'"); } }
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)); } }
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); }
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 !); } }
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 !); } }
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); } }); }
internal AsyncOperation(AsyncOperationResult result) { Result = result; State = result.IsSuccessful ? AsyncOperationState.Completed : AsyncOperationState.Failed; }
public AsyncOperation(TPass value) : base(AsyncOperationResult.Success(value)) { }
public static IAsyncOperation Fail <TException>(TException ex) where TException : Exception { return(new AsyncOperation(AsyncOperationResult.Failure(ex))); }