Exemplo n.º 1
0
        /// <summary>
        /// Scheduled a wait for the return value, then invoke the <see cref="Call{C, T}(IFiber{C}, Rest{C, T}, T)"/> method.
        /// </summary>
        public static IWait <C> Call <C, T, R>(this IFiber <C> fiber, Rest <C, T> invokeHandler, T item, Rest <C, R> returnHandler)
        {
            // tell the leaf frame of the stack to wait for the return value
            var wait = fiber.Wait(returnHandler);

            // call the child
            return(fiber.Call <C, T>(invokeHandler, item));
        }
        public Task <Message> Process(Func <IOperationContext, Task <Message> > next, IOperationContext operation)
        {
            var lockType = LockType.Write;

            if (_lockConfig != null)
            {
                lockType = _lockConfig.GetLockType(operation.Message.GetType());
            }

            return(_fiber.Call(() => next(operation), lockType));
        }
Exemplo n.º 3
0
 public async Task <IWait> NextAsync(IFiber fiber, IItem <object> ignore)
 {
     --this.count;
     if (this.count >= 0)
     {
         return(fiber.Call <T, object>(this.rest, this.item, NextAsync));
     }
     else
     {
         return(fiber.Done(this.item));
     }
 }
Exemplo n.º 4
0
 public async Task <IWait <C> > NextAsync(IFiber <C> fiber, C context, IItem <object> ignore, CancellationToken token)
 {
     --this.count;
     if (this.count >= 0)
     {
         return(fiber.Call <C, T, object>(this.rest, this.item, NextAsync));
     }
     else
     {
         return(fiber.Done(this.item));
     }
 }
Exemplo n.º 5
0
            public async Task <IWait> LoopAsync(IFiber fiber, IItem <T> item)
            {
                this.item = await item;

                --this.count;
                if (this.count >= 0)
                {
                    return(fiber.Call <T, object>(this.rest, this.item, NextAsync));
                }
                else
                {
                    return(fiber.Done(this.item));
                }
            }
Exemplo n.º 6
0
        public Task <Message> Process(Func <IOperationContext, Task <Message> > next, IOperationContext context)
        {
            LockedOperationDesc handler;

            if (_handlerByType.TryGetValue(context.Message.GetType(), out handler))
            {
                return(_fiber.Call(() => handler.ProcessFunc(context), handler.Lock));
            }
            else if (next != null)
            {
                return(next(context));
            }
            else if (_throwIfUnhandled)
            {
                throw new ProcessingException(BasicErrorCode.DispatcherFuncNotFound);
            }
            else
            {
                return(Task.FromResult <Message>(null));
            }
        }
Exemplo n.º 7
0
 // TODO: split off R to get better type inference on T
 public static IWait<C> Call<C, T, R>(this IFiber<C> fiber, Rest<C, T> invokeHandler, T item, Rest<C, R> returnHandler)
 {
     fiber.NextWait<R>().Wait(returnHandler);
     return fiber.Call<C, T>(invokeHandler, item);
 }
Exemplo n.º 8
0
 public async Task <IWait> RootAsync(IFiber fiber, IItem <T> item)
 {
     return(fiber.Call <T, object>(this.rest, await item, DoneAsync));
 }
Exemplo n.º 9
0
 public async Task <IWait <C> > RootAsync(IFiber <C> fiber, C context, IItem <T> item)
 {
     return(fiber.Call <C, T, object>(this.rest, await item, DoneAsync));
 }
Exemplo n.º 10
0
 // TODO: split off R to get better type inference on T
 public static IWait Call <T, R>(this IFiber fiber, Rest <T> invokeHandler, T item, Rest <R> returnHandler)
 {
     fiber.NextWait <R>().Wait(returnHandler);
     return(fiber.Call <T>(invokeHandler, item));
 }