コード例 #1
0
ファイル: QueueChannel.cs プロジェクト: chrisa23/Fibrous
        public void RunMultAsync(IFiberFactory factory, Func <IChannel <int> > queueFactory, int count, int wait1)
        {
            using AutoResetEvent wait = new AutoResetEvent(false);
            int hCount = 0;

            Task AsyncHandler(int s)
            {
                int c = Interlocked.Increment(ref hCount);

                if (c == OperationsPerInvoke)
                {
                    wait.Set();
                }

                NOP(wait1 / 1000.0);
                return(Task.CompletedTask);
            }

            using IChannel <int> _queue = queueFactory();
            using IDisposable fibers = new Disposables(Enumerable.Range(0, count).Select(x =>
            {
                IAsyncFiber fiber = factory.CreateAsyncFiber(ex => { });
                IDisposable sub   = _queue.Subscribe(fiber, AsyncHandler);
                return(fiber);
            }));
            for (int j = 1; j <= OperationsPerInvoke; j++)
            {
                _queue.Publish(j);
            }

            WaitHandle.WaitAny(new WaitHandle[] { wait });
        }
コード例 #2
0
        public void RunAsync(IFiberFactory factory)
        {
            using IChannel <string> _input  = new Channel <string>();
            using IChannel <string> _queue  = new QueueChannel <string>();
            using IChannel <string> _output = new Channel <string>();
            int count = 0;

            using AutoResetEvent reset = new AutoResetEvent(false);

            Task Handler1(string x)
            {
                string u = x.ToUpper();

                _queue.Publish(u);
                return(Task.CompletedTask);
            }

            Task Handler(string x)
            {
                string l = x.ToLower();

                _output.Publish(l);
                return(Task.CompletedTask);
            }

            Task Action(string x)
            {
                count++;
                if (count == OperationsPerInvoke)
                {
                    reset.Set();
                }

                return(Task.CompletedTask);
            }

            void Error(Exception e)
            {
            }

            using AsyncChannelAgent <string> fiber = new AsyncChannelAgent <string>(factory, _input, Handler1, Error);
            IDisposable[] middle = Enumerable.Range(0, 4)
                                   .Select(x => new AsyncChannelAgent <string>(factory, _queue, Handler, Error)).ToArray();
            using AsyncChannelAgent <string> fiberOut = new AsyncChannelAgent <string>(factory, _output, Action, Error);

            for (int i = 0; i < OperationsPerInvoke; i++)
            {
                _input.Publish("a");
            }

            reset.WaitOne(TimeSpan.FromSeconds(20));
            foreach (IDisposable t in middle)
            {
                t.Dispose();
            }
        }
コード例 #3
0
 public Enumerator(Action <Func <T, bool> > enumProc, IFiberFactory fiberFactory)
 {
     this.fiberFactory = fiberFactory;
     enumFiber         = fiberFactory.CreateNew(
         () => {
         enumProc(FiberNext);
         state = -1;
         mainFiber.Switch();
     }
         );
 }
コード例 #4
0
 public AsyncRequestAgent(IFiberFactory factory, Func <IRequest <TRequest, TReply>, Task> handler,
                          Action <Exception> callback)
 {
     Fiber    = factory.CreateAsyncFiber(callback);
     _channel = Fiber.NewRequestPort(handler);
 }
コード例 #5
0
 protected AsyncFiberViewModelBase(IFiberFactory factory = null) =>
コード例 #6
0
 public IterEnumerable(IIterable <T> iterable, IFiberFactory fiberFactory) : this(f => iterable.Iterate(Iterator.Create(f)), fiberFactory)
 {
 }
コード例 #7
0
 public IterEnumerable(Action <Func <T, bool> > iterProc, IFiberFactory fiberFactory)
 {
     this.iterProc     = iterProc;
     this.fiberFactory = fiberFactory;
 }
コード例 #8
0
 public RequestAgent(IFiberFactory factory, Action <IRequest <TRequest, TReply> > handler,
                     Action <Exception> errorHandler = null)
 {
     Fiber    = factory.CreateFiber(errorHandler);
     _channel = Fiber.NewRequestPort(handler);
 }
コード例 #9
0
ファイル: FiberComponent.cs プロジェクト: chrisa23/Fibrous
 protected FiberComponent(IFiberFactory factory = null) =>
コード例 #10
0
ファイル: Agent.cs プロジェクト: chrisa23/Fibrous
 public Agent(IFiberFactory factory, Action <T> handler, Action <Exception> errorCallback = null)
 {
     _handler = handler;
     Fiber    = errorCallback == null?factory.CreateFiber() : factory.CreateFiber(errorCallback);
 }
コード例 #11
0
 public AsyncChannelAgent(IFiberFactory factory, IChannel <T> channel, Func <T, Task> handler,
                          Action <Exception> errorCallback)
 {
     Fiber = factory.CreateAsyncFiber(errorCallback);
     channel.Subscribe(Fiber, handler);
 }
コード例 #12
0
 public AsyncAgent(IFiberFactory factory, Func <T, Task> handler, Action <Exception> callback)
 {
     _handler = handler;
     Fiber    = factory.CreateAsyncFiber(callback);
 }
コード例 #13
0
 protected UntypedActor(IFiberFactory factory = null)
 {
     Fiber        = factory?.CreateFiber(OnError) ?? new Fiber(OnError);
     _tellChannel = Fiber.NewChannel <object>(Receive);
     _askChannel  = Fiber.NewRequestPort <object, object>(OnRequest);
 }
コード例 #14
0
ファイル: ChannelAgent.cs プロジェクト: chrisa23/Fibrous
 public ChannelAgent(IFiberFactory factory, IChannel <T> channel, Action <T> handler,
                     Action <Exception> errorCallback = null)
 {
     Fiber = factory.CreateFiber(errorCallback);
     channel.Subscribe(Fiber, handler);
 }