Created
October 5, 2011 04:16
-
-
Save anaisbetts/1263618 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace GitHub.Tests.Helpers | |
| { | |
| public class ZeroMqRxFixture | |
| { | |
| [Test] | |
| public void ClientServerSmokeTest() | |
| { | |
| string socketAddr = "tcp://localhost:19999"; | |
| var server = ZeroMQHost<string>.Create(() => | |
| { | |
| var socket1 = new Socket(SocketType.REP); | |
| socket1.Bind(socketAddr); | |
| return new[] {socket1}; | |
| }); | |
| server.SubscribeToSocket(socketAddr) | |
| .Subscribe(x => x.Response.OnNext("***" + x.Value)); | |
| var client = ZeroMQHost<string>.Create(() => | |
| { | |
| var socket2 = new Socket(SocketType.REQ); | |
| socket2.Connect(socketAddr); | |
| return new[] {socket2}; | |
| }); | |
| string result = null; | |
| IObserver<string> sender = client.SenderForSocket(socketAddr); | |
| client.SubscribeToSocket(socketAddr) | |
| .Subscribe(x => result = x.Value); | |
| sender.OnNext("Hello"); | |
| int retries = 10; | |
| while(retries-- > 10 && result == null) | |
| { | |
| Thread.Sleep(1000); | |
| } | |
| Assert.AreEqual("***Hello", result); | |
| } | |
| } | |
| } |
Author
Nope, that's quite reasonable to me. I just try to avoid lock primitives in general, but in this case it's probably better than what I've got.
##
Paul Betts paul@paulbetts.org
…On Wednesday, October 5, 2011 at 4:31 AM, Travis Smith wrote:
Is there a reason not to use a ManualResetEvent instead of sleeping the thread on your own?
client.SubscribeToSocket(socketAddr).Subscribe(x => { result = x.Value; mre.Set(); });
mre.WaitOne(TimeSpan.FromSecond(10));
Assert.AreEqual(...)
Does that feel like cleaner/less work or is it just me?
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1263618
Just make sure you dispose of the ManualResetEvent, they leak handles.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a reason not to use a ManualResetEvent instead of sleeping the thread on your own?
client.SubscribeToSocket(socketAddr).Subscribe(x => { result = x.Value; mre.Set(); });
mre.WaitOne(TimeSpan.FromSecond(10));
Assert.AreEqual(...)
Does that feel like cleaner/less work or is it just me?