Esempio n. 1
0
        /// <summary>
        /// Creates a <see cref="IReactiveComputation{T}"/> from given source.
        /// This also creates a <see cref="RcRootSummary{T}"/> that internally represents the computation and its current result.
        /// The <see cref="IReactiveComputation{T}"/> is subscribed to the <see cref="RcRootSummary{T}"/> to be notified whenever its result changes.
        /// </summary>
        /// <typeparam name="T">Type of the result returned by the source</typeparam>
        /// <param name="computation">The actual computation, or source.</param>
        /// <returns></returns>
        public override ReactiveComputation <T> CreateReactiveComputation <T>(Func <Task <T> > computation)
        {
            var localKey = Guid.NewGuid();
            var rc       = new ReactiveComputation <T>(() =>
            {
                OutsideSummaryWorker disposed;
                WorkerMap.TryRemove(localKey.ToString(), out disposed);
                disposed.Dispose();
            });
            var RcSummary = new RcRootSummary <T>(localKey, computation, rc);
            var scheduler = new OutsideReactiveScheduler(RcSummary);
            var worker    = new OutsideSummaryWorker(RcSummary, this, scheduler);

            WorkerMap.TryAdd(localKey.ToString(), worker);
            RcSummary.EnqueueExecution();
            return(rc);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a <see cref="IReactiveComputation{T}"/> from given source.
        /// This also creates a <see cref="RcRootSummary{T}"/> that internally represents the computation and its current result.
        /// The <see cref="IReactiveComputation{T}"/> is subscribed to the <see cref="RcRootSummary{T}"/> to be notified whenever its result changes.
        /// </summary>
        /// <typeparam name="T">Type of the result returned by the source</typeparam>
        /// <param name="computation">The actual computation, or source.</param>
        /// <returns></returns>
        public override ReactiveComputation <T> CreateReactiveComputation <T>(Func <Task <T> > computation)
        {
            var localKey   = Guid.NewGuid();
            var SummaryMap = GetCurrentSummaryMap();
            var rc         = new ReactiveComputation <T>(() => {
                RcSummaryBase disposed;
                SummaryMap.TryRemove(localKey.ToString(), out disposed);
                disposed.Dispose();
            });
            var RcSummary = new RcRootSummary <T>(localKey, computation, rc);
            var success   = SummaryMap.TryAdd(localKey.ToString(), RcSummary);

            if (!success)
            {
                throw new OrleansException("Illegal State");
            }
            RcSummary.EnqueueExecution();
            return(rc);
        }
Esempio n. 3
0
 public OutsideReactiveScheduler(RcRootSummary rcRootSummary) : base()
 {
     RcRootSummary = rcRootSummary;
 }