public RetryIfCompletableSubscriber(ICompletableSubscriber actual, ICompletable source, Func <Exception, bool> retryIf) { this.actual = actual; this.source = source; this.retryIf = retryIf; }
public RetryFiniteCompletableSubscriber(ICompletableSubscriber actual, ICompletable source, long times) { this.actual = actual; this.source = source; this.remaining = times; }
public static ICompletable Timeout(this ICompletable source, TimeSpan time, IScheduler scheduler, ICompletable next) { return(Create(cs => { source.Subscribe(new TimeoutCompletableSubscriber(cs, scheduler, time, next)); })); }
public CompletableHandle <T> RegisterCompletable <T>(ICompletable <T> completable) { var handle = new CompletableHandle <T>(completable); PendingCompletables.Add(handle); return(handle); }
public static ISingle <T> ToSingle <T>(this ICompletable source, Func <T> successValueSupplier) { return(Single.Create <T>(cs => { source.Subscribe(new ToSingleCompletableSubscriber <T>(cs, successValueSupplier)); })); }
public static ICompletable Delay(this ICompletable source, TimeSpan time, IScheduler scheduler, bool delayError = false) { return(Create(cs => { source.Subscribe(new DelayCompletableSubscriber(cs, scheduler, time, delayError)); })); }
private static void SharedCompleteSyncOrAsync(ICompletable operation) { if (!operation.TryComplete(false)) { SocketManager.Shared.ScheduleTask(s_AnyOrderCompletionHandler, operation); } }
public static ICompletable OnErrorResumeNext(this ICompletable source, Func <Exception, ICompletable> nextSelector) { return(Create(cs => { source.Subscribe(new ResumeCompletableSubscriber(cs, nextSelector)); })); }
public void ShowLoadingWindow(Context context, ICompletable completable) { App.Current.Dispatcher.Invoke(() => { BoxHelper.ShowLoadingDialog(completable); }); }
public static ICompletable OnErrorComplete(this ICompletable source, Func <Exception, bool> predicate) { return(Create(cs => { source.Subscribe(new OnErrorCompleteCompletableSubscriber(cs, predicate)); })); }
internal static void CompleteAsWorker(ICompletable completable) { if (completable != null) { ThreadPool.QueueUserWorkItem(s_CompleteAsWorker, completable); } }
public void CompleteSyncOrAsync(ICompletable operation) { if (operation == null) return; if (operation.TryComplete(false)) { multiplexer.Trace("Completed synchronously: " + operation, name); Interlocked.Increment(ref completedSync); return; } else { if (multiplexer.PreserveAsyncOrder) { multiplexer.Trace("Queueing for asynchronous completion", name); bool startNewWorker; lock (asyncCompletionQueue) { asyncCompletionQueue.Enqueue(operation); startNewWorker = asyncCompletionQueue.Count == 1; } if (startNewWorker) { multiplexer.Trace("Starting new async completion worker", name); OnCompletedAsync(); ThreadPool.QueueUserWorkItem(processAsyncCompletionQueue, this); } } else { multiplexer.Trace("Using thread-pool for asynchronous completion", name); ThreadPool.QueueUserWorkItem(anyOrderCompletionHandler, operation); Interlocked.Increment(ref completedAsync); // k, *technically* we haven't actually completed this yet, but: close enough } } }
public static IDisposable Subscribe <T>(this ICompletable source, IObserver <T> observer) { ObserverToCompletableSubscriber <T> s = new ObserverToCompletableSubscriber <T>(observer); source.Subscribe(s); return(s); }
public static IDisposable Subscribe(this ICompletable source, Action onCompleteCall, Action <Exception> onErrorCall) { CallbackCompletableSubscriber ccs = new CallbackCompletableSubscriber(onCompleteCall, onErrorCall); source.Subscribe(ccs); return(ccs); }
public static bool Await(this ICompletable source, TimeSpan timeout) { LatchedCompletableSubscriber lcs = new LatchedCompletableSubscriber(); source.Subscribe(lcs); return(lcs.Await(timeout)); }
public static void Await(this ICompletable source) { LatchedCompletableSubscriber lcs = new LatchedCompletableSubscriber(); source.Subscribe(lcs); lcs.Await(); }
public TimeoutCompletableSubscriber(ICompletableSubscriber actual, IScheduler scheduler, TimeSpan timeout, ICompletable other) { this.actual = actual; this.scheduler = scheduler; this.timeout = timeout; this.other = other; }
public static ICompletable Retry(this ICompletable source, long times) { return(Create(cs => { RetryFiniteCompletableSubscriber rics = new RetryFiniteCompletableSubscriber(cs, source, times); rics.Resubscribe(); })); }
public static ICompletable Retry(this ICompletable source, Func <Exception, bool> retryIf) { return(Create(cs => { RetryIfCompletableSubscriber rics = new RetryIfCompletableSubscriber(cs, source, retryIf); rics.Resubscribe(); })); }
/// <summary> /// Try to step the state forward. returns false if done stepping /// </summary> /// <returns></returns> public virtual bool TryStep() { if (currentState.IsComplete() || IsDisposed) { return(false); } currentState = currentState.StepNext(); return(true); }
public static ICompletable UnsubscribeOn(this ICompletable source, IScheduler scheduler) { return(Create(cs => { UnsubscribeOnCompletableSubscriber oocs = new UnsubscribeOnCompletableSubscriber(cs, scheduler); source.Subscribe(oocs); })); }
public static void ShowLoadingDialog(ICompletable completable) { if (_loadingWindowIsAlreadyHaveOne) { return; } _loadingWindowIsAlreadyHaveOne = true; new LoadingWindow(_owner).ShowDialog(completable); _loadingWindowIsAlreadyHaveOne = false; }
public static ICompletable DoAfterTerminate(this ICompletable source, Action onAfterTerminateCall) { return(Create(cs => { LambdaCompletableSubscriber lcs = new LambdaCompletableSubscriber( cs, d => { }, () => { }, e => { }, onAfterTerminateCall); source.Subscribe(lcs); })); }
public static ICompletable DoOnError(this ICompletable source, Action <Exception> onErrorCall) { return(Create(cs => { LambdaCompletableSubscriber lcs = new LambdaCompletableSubscriber( cs, d => { }, () => { }, onErrorCall, () => { }); source.Subscribe(lcs); })); }
/// <summary> /// Tries to add given completable at the end of sequence, but if completable was already /// present in sequence, truncate everything after it instead. /// </summary> /// <returns>True if completable was added at the end of sequence, or False if completable /// was already present in sequence and everything after it was truncated instead.</returns> public static bool AddOrTruncateAfter(this LiveSequence This, ICompletable completable) { if (This.TruncateAfter(completable)) { return(false); } This.Add(completable); return(true); }
// this chains some try/finally blocks to // - complete and dispose the scoped filesystems // - deal with events if appropriate // - remove the scope context if it belongs to this scope // - deal with detachable scopes // here, // - completed indicates whether the scope has been completed // can be true or false, but in both cases the scope is exiting // in a normal way // - onException indicates whether completing/aborting the database // transaction threw an exception, in which case 'completed' has // to be false + events don't trigger and we just to some cleanup // to ensure we don't leave a scope around, etc private void RobustExit(bool completed, bool onException) { if (onException) { completed = false; } TryFinally(() => { if (_scopeFileSystem == true) { if (completed) { _fscope.Complete(); } _fscope.Dispose(); _fscope = null; } }, () => { // deal with events if (onException == false && _eventDispatcher != null) { _eventDispatcher.ScopeExit(completed); } }, () => { // if *we* created it, then get rid of it if (_scopeProvider.AmbientContext == _scopeContext) { try { _scopeProvider.AmbientContext.ScopeExit(completed); } finally { // removes the ambient context (ambient scope already gone) _scopeProvider.SetAmbient(null); } } }, () => { if (Detachable) { // get out of the way, restore original _scopeProvider.SetAmbient(OrigScope, OrigContext); Attached = false; OrigScope = null; OrigContext = null; } }); }
internal static void CompleteAsync(CompletionManager manager, ICompletable operation) { var sched = manager.multiplexer.SocketManager; if (sched != null) { sched.ScheduleTask(s_AnyOrderCompletionHandler, operation); Interlocked.Increment(ref manager.completedAsync); } else { SocketManager.Shared.ScheduleTask(s_AnyOrderCompletionHandler, operation); } }
internal static void CompleteSyncOrAsyncImpl(CompletionManager manager, ICompletable operation) { if (operation == null) { return; } if (manager != null) { manager.PerInstanceCompleteSyncOrAsync(operation); } else { SharedCompleteSyncOrAsync(operation); } }
public static ICompletable DelaySubscription(this ICompletable source, TimeSpan delay, IScheduler scheduler) { return(Create(cs => { MultipleAssignmentDisposable t = new MultipleAssignmentDisposable(); MultipleAssignmentDisposable mad = new MultipleAssignmentDisposable(t); cs.OnSubscribe(mad); t.Set(scheduler.ScheduleDirect(() => { source.Subscribe(new SubscribeOnCompletableSubscriber(cs, mad)); }, delay)); })); }
public void ShowDialog(ICompletable flowOrFm) { BtnCancel.Visibility = Visibility.Visible; flowOrFm.NoArgFinished += (s, e) => { this.Dispatcher.Invoke(() => { Close(); }); }; this.BtnCancel.Click += (s, e) => { flowOrFm.ForceStop(); Close(); }; base.ShowDialog(); }
public static ICompletable SubscribeOn(this ICompletable source, IScheduler scheduler) { return(Create(cs => { MultipleAssignmentDisposable inner = new MultipleAssignmentDisposable(); MultipleAssignmentDisposable outer = new MultipleAssignmentDisposable(inner); cs.OnSubscribe(outer); inner.Set(scheduler.ScheduleDirect(() => { source.Subscribe(new SubscribeOnCompletableSubscriber(cs, outer)); })); })); }
public void CompleteSyncOrAsync(ICompletable operation) { completionManager.CompleteSyncOrAsync(operation); }