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 }); }
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(); } }
public Enumerator(Action <Func <T, bool> > enumProc, IFiberFactory fiberFactory) { this.fiberFactory = fiberFactory; enumFiber = fiberFactory.CreateNew( () => { enumProc(FiberNext); state = -1; mainFiber.Switch(); } ); }
public AsyncRequestAgent(IFiberFactory factory, Func <IRequest <TRequest, TReply>, Task> handler, Action <Exception> callback) { Fiber = factory.CreateAsyncFiber(callback); _channel = Fiber.NewRequestPort(handler); }
protected AsyncFiberViewModelBase(IFiberFactory factory = null) =>
public IterEnumerable(IIterable <T> iterable, IFiberFactory fiberFactory) : this(f => iterable.Iterate(Iterator.Create(f)), fiberFactory) { }
public IterEnumerable(Action <Func <T, bool> > iterProc, IFiberFactory fiberFactory) { this.iterProc = iterProc; this.fiberFactory = fiberFactory; }
public RequestAgent(IFiberFactory factory, Action <IRequest <TRequest, TReply> > handler, Action <Exception> errorHandler = null) { Fiber = factory.CreateFiber(errorHandler); _channel = Fiber.NewRequestPort(handler); }
protected FiberComponent(IFiberFactory factory = null) =>
public Agent(IFiberFactory factory, Action <T> handler, Action <Exception> errorCallback = null) { _handler = handler; Fiber = errorCallback == null?factory.CreateFiber() : factory.CreateFiber(errorCallback); }
public AsyncChannelAgent(IFiberFactory factory, IChannel <T> channel, Func <T, Task> handler, Action <Exception> errorCallback) { Fiber = factory.CreateAsyncFiber(errorCallback); channel.Subscribe(Fiber, handler); }
public AsyncAgent(IFiberFactory factory, Func <T, Task> handler, Action <Exception> callback) { _handler = handler; Fiber = factory.CreateAsyncFiber(callback); }
protected UntypedActor(IFiberFactory factory = null) { Fiber = factory?.CreateFiber(OnError) ?? new Fiber(OnError); _tellChannel = Fiber.NewChannel <object>(Receive); _askChannel = Fiber.NewRequestPort <object, object>(OnRequest); }
public ChannelAgent(IFiberFactory factory, IChannel <T> channel, Action <T> handler, Action <Exception> errorCallback = null) { Fiber = factory.CreateFiber(errorCallback); channel.Subscribe(Fiber, handler); }