public Ponger() { _fiber = new PoolFiber(); Pinged = new Future<Ping>(); PongChannel = new ConsumerChannel<Ping>(_fiber, HandlePing); }
public SomeActorInstance() { _fiber = new PoolFiber(); _future = new Future<MyMessage>(); MessageChannel = new ConsumerChannel<MyMessage>(_fiber, Consume); LambdaMessageChannel = new ConsumerChannel<MyMessage>(_fiber, message => _future.Complete(message)); }
public void Should_properly_wrap_the_channel_as_synchronized() { Assert.IsNull(SynchronizationContext.Current); var fiber = new PoolFiber(); var input = new ChannelAdapter(); var context = new TestSynchronizationContext(); var future = new Future<TestMessage>(); SynchronizationContext.SetSynchronizationContext(context); Assert.IsNotNull(SynchronizationContext.Current); using (input.Connect(x => { x.AddConsumerOf<TestMessage>() .OnCurrentSynchronizationContext() .UsingConsumer(message => { Trace.WriteLine("Received on Thread: " + Thread.CurrentThread.ManagedThreadId); Assert.IsNotNull(SynchronizationContext.Current); Assert.AreEqual(context, SynchronizationContext.Current); future.Complete(message); }); })) { Trace.WriteLine("Subscribed on Thread: " + Thread.CurrentThread.ManagedThreadId); SynchronizationContext.SetSynchronizationContext(null); input.Flatten().Select(c => c.GetType()).ShouldEqual(new[] { typeof(ChannelAdapter), typeof(BroadcastChannel), typeof(TypedChannelAdapter<TestMessage>), typeof(SynchronizedChannel<TestMessage>), typeof(ConsumerChannel<TestMessage>), }); fiber.Add(() => { Trace.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId); Assert.IsNull(SynchronizationContext.Current); input.Send(new TestMessage()); }); Assert.IsNull(SynchronizationContext.Current); future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue(); } }