本文整理汇总了C#中Future.Complete方法的典型用法代码示例。如果您正苦于以下问题:C# Future.Complete方法的具体用法?C# Future.Complete怎么用?C# Future.Complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Future
的用法示例。
在下文中一共展示了Future.Complete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: An_exception_is_thrown
public void An_exception_is_thrown()
{
var future = new Future<object>();
var obj1 = new object();
var obj2 = new object();
future.Complete(obj1);
Assert.That(() => future.Complete(obj2), Throws.TypeOf<InvalidOperationException>());
}
示例2: Should_properly_arrive_at_the_destination
public void Should_properly_arrive_at_the_destination()
{
var serviceUri = new Uri("net.pipe://localhost/pipe");
string pipeName = "test";
var future = new Future<TestMessage>();
var message = new TestMessage
{
Id = Guid.NewGuid(),
Name = "Alpha",
};
UntypedChannel adapter = new ChannelAdapter();
using (var remote = new WcfChannelHost(new SynchronousFiber(), adapter, serviceUri, pipeName))
{
using (adapter.Connect(x =>
{
x.AddConsumerOf<TestMessage>()
.UsingConsumer(m => future.Complete(m));
}))
{
var client = new WcfChannelProxy(new SynchronousFiber(), serviceUri, pipeName);
client.Send(message);
future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
}
}
future.Value.ShouldNotBeNull();
future.Value.ShouldEqual(message);
future.Value.ShouldNotBeTheSameAs(message);
}
示例3: Should_property_adapt_itself_to_a_channel_network
public void Should_property_adapt_itself_to_a_channel_network()
{
TraceLogger.Configure(LogLevel.Debug);
ILogger log = Logger.GetLogger<Sending_a_message_through_a_wcf_channel>();
log.Debug("Starting");
var serviceUri = new Uri("net.pipe://localhost/Pipe");
string pipeName = "Test";
Channel<TestMessage> adapter = new ChannelAdapter<TestMessage>();
using (var host = new WcfChannelHost<TestMessage>(adapter, serviceUri, pipeName))
{
log.Debug("Host started");
var future = new Future<TestMessage>();
using (adapter.Connect(x =>
{
x.AddConsumer(m =>
{
log.Debug(l => l.Write("Received: {0}", m.Value));
future.Complete(m);
});
}))
{
var client = new WcfChannelProxy<TestMessage>(new SynchronousFiber(), serviceUri, pipeName);
log.Debug("Client started");
client.Send(new TestMessage("Hello!"));
future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
log.Debug("Complete");
}
}
}
示例4: Should_support_the_username_password_for_a_host
public void Should_support_the_username_password_for_a_host()
{
var inputAddress = new Uri("rabbitmq://localhost/mt/test_queue");
var future = new Future<IConsumeContext<A>>();
using (IServiceBus bus = ServiceBusFactory.New(c =>
{
c.ReceiveFrom(inputAddress);
c.UseRabbitMq(r =>
{
r.ConfigureHost(inputAddress, h =>
{
h.SetUsername("testUser");
h.SetPassword("test");
});
});
c.Subscribe(s => s.Handler<A>((context, message) => future.Complete(context)));
}))
{
bus.Publish(new A());
Assert.IsTrue(future.WaitUntilCompleted(TimeSpan.FromSeconds(8)));
}
Assert.AreEqual(inputAddress.ToString(), future.Value.SourceAddress.ToString());
}
示例5: Adding_operations_to_a_fiber
public void Adding_operations_to_a_fiber()
{
_count = 10000;
_values = new int[_count];
Fiber fiber = new PoolFiber();
int index = 0;
var completed = new Future<int>();
var go = new Future<bool>();
fiber.Add(() => { go.WaitUntilCompleted(10.Seconds()); });
for (int i = 0; i < _count; i++)
{
int offset = i;
fiber.Add(() =>
{
_values[offset] = index++;
if (offset == _count - 1)
completed.Complete(offset);
});
}
go.Complete(true);
completed.WaitUntilCompleted(10.Seconds()).ShouldBeTrue();
}
示例6: query_internal_state
protected static EventHeapState query_internal_state()
{
var reply = new Future<EventHeapState>();
AnonymousActor.New(inbox => eventFilter.Request<QueryInternals>(inbox).Receive<EventHeapState>(msg => reply.Complete(msg)));
reply.WaitUntilCompleted(-1);
return reply.Value;
}
示例7: InvokesOnCompletesWhenCompleted
public void InvokesOnCompletesWhenCompleted () {
var f = new Future<object>();
object completeResult = null;
f.RegisterOnComplete((_) => { completeResult = _.Error ?? _.Result; });
f.Complete(5);
Assert.AreEqual(5, completeResult);
}
示例8: Read
public Future<int> Read (byte[] buffer, int offset, int count) {
var f = new Future<int>();
if (!_Socket.Connected) {
if (ThrowOnDisconnect)
f.Fail(new SocketDisconnectedException());
else
f.Complete(0);
} else {
SocketError errorCode;
if (_Socket.Available >= count) {
try {
int bytesRead = _Socket.Receive(buffer, offset, count, SocketFlags.None, out errorCode);
if (ThrowOnDisconnect && (bytesRead == 0)) {
f.Fail(new SocketDisconnectedException());
} else {
f.Complete(bytesRead);
}
} catch (Exception ex) {
f.Fail(ex);
}
} else {
_Socket.BeginReceive(buffer, offset, count, SocketFlags.None, out errorCode, _ReadCallback, f);
}
}
return f;
}
示例9: Should_be_fast
public void Should_be_fast()
{
Fiber fiber = new ThreadPoolFiber();
const int limit = 5000000;
var complete = new Future<int>();
Channel<MsgStruct> channel = new ConsumerChannel<MsgStruct>(fiber, message =>
{
if (message.Count == limit)
complete.Complete(limit);
});
using (var timer = new FunctionTimer("Throughput", x =>
{
Trace.WriteLine("Time to execute: " + (int) x.ElapsedMilliseconds + "ms");
Trace.WriteLine("Per second throughput: " + (int) (limit/(x.ElapsedMilliseconds/1000)));
}))
{
for (int i = 1; i <= limit; i++)
{
channel.Send(new MsgStruct
{
Count = i,
Other = i*8,
});
}
timer.Mark();
complete.WaitUntilCompleted(30.Seconds()).ShouldBeTrue();
}
}
示例10: Should_have_the_bits_without_the_message_first
public void Should_have_the_bits_without_the_message_first()
{
var engine = new DynamicRoutingEngine(new PoolFiber());
var visualizer = new TraceRoutingEngineVisualizer();
var received = new Future<A>();
engine.Configure(x => x.Receive<A>(received.Complete));
var block = new Future<int>();
engine.Add(0, () =>
{
visualizer.Show(engine);
block.Complete(0);
});
block.WaitUntilCompleted(2.Seconds());
engine.Send(new A());
received.WaitUntilCompleted(2.Seconds());
engine.Send(new B());
var receivedB = new Future<B>();
engine.Configure(x => x.Receive<B>(receivedB.Complete));
received.WaitUntilCompleted(8.Seconds()).ShouldBeTrue();
receivedB.WaitUntilCompleted(8.Seconds()).ShouldBeTrue();
//engine.Receive<A, B>(x => { });
visualizer.Show(engine);
}
示例11: A_file_is_created
public void A_file_is_created()
{
_baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
_filename = "test2.dat";
_path = Path.Combine(_baseDirectory, _filename);
System.IO.File.Delete(_path);
_listener = new Future<FileCreated>();
_channel = new ChannelAdapter();
FiberFactory fiberFactory = () => new SynchronousFiber();
_scheduler = new TimerScheduler(fiberFactory());
_producer = new PollingFileSystemEventProducer(_baseDirectory, _channel, _scheduler, fiberFactory(),
20.Seconds());
Thread.Sleep(5.Seconds());
using (_channel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(m => _listener.Complete(m))))
{
System.IO.File.Create(_path);
_listener.WaitUntilCompleted(25.Seconds());
}
_producer.Dispose();
}
示例12: A_loopback_registry
public void A_loopback_registry()
{
Address = new Uri("loopback://localhost/");
ReceivedA = new Future<A>();
Registry = ActorRegistryFactory.New(x =>
{
x.Remote(r =>
{
r.ListenTo(Address);
});
});
ActorId = Guid.NewGuid();
Actor = AnonymousActor.New(inbox =>
{
inbox.Loop(loop =>
{
loop.Receive<Message<A>>(message =>
{
ReceivedA.Complete(message.Body);
loop.Continue();
});
});
});
Registry.Register(ActorId, Actor);
}
示例13: SomeActorInstance
public SomeActorInstance()
{
_fiber = new PoolFiber();
_future = new Future<MyMessage>();
MessageChannel = new ConsumerChannel<MyMessage>(_fiber, Consume);
LambdaMessageChannel = new ConsumerChannel<MyMessage>(_fiber, message => _future.Complete(message));
}
示例14: ConfigureServiceBus
protected override void ConfigureServiceBus(Uri uri, ServiceBusConfigurator configurator)
{
base.ConfigureServiceBus(uri, configurator);
_received = new Future<A>();
configurator.Subscribe(x => { x.Handler<A>(msg => _received.Complete(msg)); });
}
示例15: ConfigureServiceBus
protected override void ConfigureServiceBus(Uri uri, ServiceBusConfigurator configurator)
{
_received = new Future<A>();
configurator.Subscribe(s => s.Handler<A>(message => _received.Complete(message)));
configurator.UseControlBus();
configurator.UseStomp();
}