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(); }
internal void Accept(object?result) { State = AsyncOperationState.Completed; Result = AsyncOperationResult.Success(result); while (_continuations.TryDequeue(out var continuation)) { continuation.Dispatch(Result.Value); } }
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)); }
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)); } }
internal virtual AsyncOperationResult Handle(Exception exception) { if (_catchHandlers.TryHandle(exception)) { return(AsyncOperationResult.Success()); } else { return(AsyncOperationResult.Failure(exception)); } }
internal override AsyncOperationResult Handle(Exception exception) { TPass resultValue; if (_catchHandlers.TryHandle(exception, out resultValue)) { return(AsyncOperationResult.Success(resultValue)); } else { return(AsyncOperationResult.Failure(exception)); } }
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 (_actionHandle.Resolve()) { try { return(_result = AsyncOperationResult.Success(_action(arg))); } catch (Exception ex) { return(_result = AsyncOperationResult.Failure(ex)); } } else { return(_result !); } }
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 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); } }); }
public AsyncOperation(TPass value) : base(AsyncOperationResult.Success(value)) { }