Esempio n. 1
0
 public void RunWhenDue(Action action)
 {
     _subscription = _timeEverySecond.Subscribe(now =>
     {
         if (IsDue(now))
         {
             action.Invoke();
         }
     });
 }
Esempio n. 2
0
        private static ISubscription SubscribeRoot <T>(ISubscribable <T> source, IObserver <T> observer)
        {
            var sub = source.Subscribe(observer);

            if (observer is ISubscription o)
            {
                return(new StableCompositeSubscription(sub, o));
            }

            return(sub);
        }
        /// <summary>
        /// Subscribes the specified source.
        /// </summary>
        /// <typeparam name="T">Type of events.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="res">The result observer.</param>
        /// <param name="context">The context.</param>
        /// <returns>Subscription.</returns>
        public static ISubscription Subscribe <T>(this ISubscribable <T> source, IObserver <T> res, IOperatorContext context)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            ISubscription sub = source.Subscribe(res);

            new SubscriptionInitializeVisitor(sub).Initialize(context);
            return(sub);
        }
        /// <summary>
        /// Target for binding rx://builtin/subscribe. Supports visiting the subscription as well as the observer (e.g. for purposes
        /// of state persistence).
        /// </summary>
        /// <typeparam name="T">The type of the elements.</typeparam>
        /// <param name="subscribable">The observable to subscribe to.</param>
        /// <param name="observer">The observer to use for the subscription.</param>
        /// <returns>The subscription object which supports traversal using subscription visitors.</returns>
        public static ISubscription SubscribeRoot <T>(this ISubscribable <T> subscribable, IObserver <T> observer)
        {
            var subscription = subscribable.Subscribe(observer);

            //
            // NB: Subscription is a bit of a misnomer; it's merely a mechanism to visit nodes in a query tree. As such, an observer
            //     can implement `ISubscription` and be reachable by visitors (e.g. to save/load state, to support IUnloadable, etc.).
            //

            if (observer is ISubscription o)
            {
                subscription = StaticCompositeSubscription.Create(subscription, o);
            }

            return(subscription);
        }
        /// <summary>
        /// Subscribes to an inner sequence using the given observer. The inner sequence should have
        /// an expression representation in order for the subscription to be checkpointable. If the
        /// observer has state that needs to be checkpointed, it should implement load and save
        /// functionality using the IStatefulOperator interface. The returned subscription object is
        /// cold and needs to be activated by the caller.
        /// </summary>
        /// <typeparam name="TInner">Element type of the inner sequence.</typeparam>
        /// <param name="inner">Inner sequence to subscribe to.</param>
        /// <param name="observer">Observer to subscribe to the inner sequence.</param>
        /// <returns>
        /// Subscription to the inner sequence. The caller is responsible to activate the subscription.
        /// In order to save and load the subscription for use in checkpointing, the LoadInner and
        /// SaveInner methods should be used.
        /// </returns>
        protected ISubscription SubscribeInner <TInner>(ISubscribable <TInner> inner, IObserver <TInner> observer)
        {
            if (TryGetHigherOrderExecutionEnvironment(out var env))
            {
                return(env.CreateBridge(inner, observer, _context));
            }
            else
            {
                //
                // NB: This has been put in to allow the library to be used in a way similar to classic Rx,
                //     outside a hosting environment.
                //

#pragma warning disable IDE0079 // Remove unnecessary suppression.
#pragma warning disable CA1062  // Validate arguments of public methods. (Derived classes should not pass null.)

                return(inner.Subscribe(observer));

#pragma warning restore CA1062
#pragma warning restore IDE0079
            }
        }
Esempio n. 6
0
 public void RunWhenDue(Action action)
 {
     _canRun       = true;
     _subscription = _metronome.Subscribe(RunOnce);
 }