예제 #1
0
        /// <summary>
        ///    Executes the Eff computation using semantics from the provided effect handler.
        /// </summary>
        /// <param name="effectHandler">Effect handler to be used in execution.</param>
        /// <returns>A task computing the result of the eff computation.</returns>
        public async Task Run(IEffectHandler effectHandler)
        {
            var awaiter = GetAwaiterCore();
            await awaiter.Accept(effectHandler).ConfigureAwait(false);

            awaiter.GetResult();
        }
예제 #2
0
        public void Setup()
        {
            const int offset = 50_000; // prevent task caching from kicking in

            _data    = Enumerable.Range(0, 100).Select(x => x + offset).ToArray();
            _handler = new DefaultEffectHandler();
        }
예제 #3
0
파일: Effect.cs 프로젝트: rmdouglas/Eff
        /// <summary>
        ///   Executes the Effect using semantics from the provided effect handler.
        /// </summary>
        /// <param name="effectHandler">Effect handler to be used in execution.</param>
        /// <returns>A task computing the result of the Effect.</returns>
        public async Task <TResult> Run(IEffectHandler effectHandler)
        {
            var effectAwaiter = new EffectAwaiter <TResult>(this);
            await effectHandler.Handle(effectAwaiter).ConfigureAwait(false);

            return(effectAwaiter.GetResult());
        }
예제 #4
0
        public static async Task <TResult> Run <TResult>(this Eff <TResult> eff, IEffectHandler handler)
        {
            if (eff == null)
            {
                throw new ArgumentNullException(nameof(eff));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }


            var result = default(TResult);
            var done   = false;

            while (!done)
            {
                switch (eff)
                {
                case SetException <TResult> setException:
                    await handler.Handle(setException);

                    break;

                case SetResult <TResult> setResult:
                    result = await handler.Handle(setResult);

                    done = true;
                    break;

                case Delay <TResult> delay:
                    eff = await handler.Handle(delay);

                    break;

                case Await <TResult> awaitEff:
                    eff = await handler.Handle(awaitEff);

                    break;

                default:
                    throw new NotSupportedException($"{eff.GetType().Name}");
                }
            }

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Runs supplied Eff computation using provided effect handler.
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="eff">Eff computation to be run.</param>
        /// <param name="handler">Effect handler to be used in execution.</param>
        public static async Task <TResult> Run <TResult>(this Eff <TResult> eff, IEffectHandler handler)
        {
            var result = default(TResult) !;
            var done   = false;

            while (!done)
            {
                switch (eff)
                {
                case ExceptionEff <TResult> setException:
                    await handler.Handle(setException);

                    break;

                case ResultEff <TResult> setResult:
                    result = await handler.Handle(setResult);

                    done = true;
                    break;

                case DelayEff <TResult> delay:
                    eff = await handler.Handle(delay);

                    break;

                case AwaitEff <TResult> awaitEff:
                    eff = await handler.Handle(awaitEff);

                    break;

                default:
                    throw new NotSupportedException($"{eff.GetType().Name}");
                }
            }

            return(result);
        }
예제 #6
0
 /// <summary>
 /// Runs supplied Eff computation using provided effect handler.
 /// </summary>
 /// <typeparam name="TResult"></typeparam>
 /// <param name="eff">Eff computation to be run.</param>
 /// <param name="handler">Effect handler to be used in execution.</param>
 public static Task Run(this Eff eff, IEffectHandler handler) => eff.RunCore(handler);
예제 #7
0
 public override Task Accept(IEffectHandler handler)
 {
     SetException(new DivideByZeroException());
     throw new NotImplementedException();
 }
예제 #8
0
 public override Task Accept(IEffectHandler handler)
 {
     return(handler.Handle(this));
 }
예제 #9
0
 /// <summary>
 ///   Processes the awaiter using the provided effect handler.
 /// </summary>
 public override ValueTask Accept(IEffectHandler handler) => handler.Handle(this);
예제 #10
0
파일: Eff.cs 프로젝트: ivan-codes-foss/Eff
 /// <summary>
 /// Helper method for interpreting untyped Eff instances
 /// </summary>
 internal abstract Task RunCore(IEffectHandler handler);
예제 #11
0
 public ValuesController()
 {
     handler = new DefaultEffectHandler();
 }
예제 #12
0
파일: Effect.cs 프로젝트: stuarthillary/Eff
 public virtual Task Accept(IEffectHandler handler)
 {
     return(handler.Handle(this));
 }
예제 #13
0
 public void Setup()
 {
     _data    = Enumerable.Range(1, 100).ToArray();
     _handler = new DefaultEffectHandler();
 }
예제 #14
0
 public abstract Task Accept(IEffectHandler handler);
예제 #15
0
 public PushEffectHandlerEffect(IEffectHandler handler)
 {
     Handler = handler;
 }
예제 #16
0
 public static PushEffectHandlerEffect Push(IEffectHandler handler) => new PushEffectHandlerEffect(handler);