Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created October 28, 2011 22:10
Show Gist options
  • Select an option

  • Save anaisbetts/1323712 to your computer and use it in GitHub Desktop.

Select an option

Save anaisbetts/1323712 to your computer and use it in GitHub Desktop.
const string socketAddr = "tcp://localhost:30101";
public IObservable<bool> ConnectOrBecomeAnnounceServer()
{
if (_socket != null)
{
return Observable.Throw<bool>(new Exception("Already connected"));
}
return ConnectToAnnounceServer()
.Catch(BecomeAnnounceServer())
.SelectMany(sockAndCtx =>
{
if (sockAndCtx == null)
{
return Observable.Throw<bool>(new Exception("Can't connect nor become announce server"));
}
_socket = _host.RegisterSocket(sockAndCtx.Item1);
_isAnnounceServer = sockAndCtx.Item2;
return Observable.Return(_isAnnounceServer);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment