public static IRxVal <Option <A> > toRxVal <A>(this Future <A> future) { var rx = RxRef.a(F.none <A>()); future.onComplete(a => rx.value = F.some(a)); return(rx); }
public static IRxVal <B> toRxVal <A, B>(this Future <A> future, B whileNotCompleted, Fn <A, B> onCompletion) { var rx = RxRef.a(whileNotCompleted); future.onComplete(a => rx.value = onCompletion(a)); return(rx); }
public static IRxVal <A> toRxVal <A>(this Future <A> future, A whileNotCompleted) { var rx = RxRef.a(whileNotCompleted); future.onComplete(a => rx.value = a); return(rx); }
/** * Takes a function that transforms an element into a future and * applies it to all elements in given sequence. * * However instead of applying all elements concurrently it waits * for the future from previous element to complete before applying * the next element. * * Returns reactive value that can be used to observe current stage * of the application. **/ public static IRxVal <Option <B> > inAsyncSeq <A, B>( this IEnumerable <A> enumerable, Fn <A, Future <B> > asyncAction ) { var rxRef = RxRef.a(F.none <B>()); inAsyncSeq(enumerable.GetEnumerator(), rxRef, asyncAction); return(rxRef); }
public static IRxVal <A> toRxVal <A>( this Future <IRxVal <A> > future, A whileNotCompleted ) { var rx = RxRef.a(whileNotCompleted); future.onComplete(rx2 => rx2.subscribe(v => rx.value = v)); return(rx); }
public void WithRxValInside() { Promise <IRxVal <int> > p; var f = Future <IRxVal <int> > .async(out p); var rx = f.toRxVal(0); rx.value.shouldEqual(0); var rx2 = RxRef.a(100); p.complete(rx2); rx.value.shouldEqual(100); rx2.value = 200; rx.value.shouldEqual(200); }
/*********** Two-way binds ***********/ public static ISubscription bind <T>( this IRxRef <T> subject, IEnumerable <dfCheckbox> checkboxes, Fn <T, string> mapper, Fn <string, T> comapper ) { var optSubject = RxRef.a(F.some(subject.value)); var optSubjectSourceSubscription = subject.subscribe(v => optSubject.value = F.some(v) ); var optSubjectTargetSubscription = optSubject.subscribe(opt => opt.each(v => subject.value = v) ); var bindSubscription = optSubject.bind(checkboxes, mapper, comapper); return(new Subscription(() => { optSubjectSourceSubscription.unsubscribe(); optSubjectTargetSubscription.unsubscribe(); bindSubscription.unsubscribe(); })); }
/// <summary> /// This class calculates realtimeSinceStartup, /// but excludes time intervals when an ad is showing or application is paused /// /// on android - interstitials usually run on a separate activity (application gets paused/resumed automatically) /// on IOS and some android ad networks - application does not get paused, so we need to call `setPaused` ourselves /// </summary> RealTimeButPauseWhenAdIsShowing() { var pauseStarted = Time.realtimeSinceStartup; externalPause = RxRef.a(false); ASync.onAppPause.toRxVal(false).zip(externalPause, F.or2).subscribeWithoutEmit( NeverDisposeDisposableTracker.instance, paused => { isPaused = paused; if (paused) { pauseStarted = Time.realtimeSinceStartup; } else { var secondsPaused = Time.realtimeSinceStartup - pauseStarted; totalSecondsPaused += secondsPaused; } } ); }