本文整理汇总了C#中AsyncSubject.Timeout方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncSubject.Timeout方法的具体用法?C# AsyncSubject.Timeout怎么用?C# AsyncSubject.Timeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncSubject
的用法示例。
在下文中一共展示了AsyncSubject.Timeout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EstablishEncryptionAsync
public virtual IObservable<bool> EstablishEncryptionAsync()
{
ValidateDisposed();
var future = new AsyncSubject<bool>();
var watchStatusChanged = new SingleAssignmentDisposable();
watchStatusChanged.Disposable = this.ObserveStatusChanged().Subscribe(x =>
{
if (x == StatusCode.EncryptionFailedToEstablish)
{
watchStatusChanged.Dispose();
future.OnError(new EncryptionFailedToEstablishException());
}
if (x == StatusCode.EncryptionEstablished)
{
watchStatusChanged.Dispose();
future.OnNext(true);
future.OnCompleted();
}
});
if (this.EstablishEncryption())
{
return future.Timeout(Timeout).Catch((Exception ex) =>
{
watchStatusChanged.Dispose();
this.Disconnect();
return Observable.Throw<bool>(ex);
});
}
else
{
watchStatusChanged.Dispose();
return Observable.Return(false);
}
}
示例2: ConnectAsync
public virtual IObservable<bool> ConnectAsync(string serverAddress, string applicationName)
{
ValidateDisposed();
var future = new AsyncSubject<bool>();
var watchStatusChanged = new SingleAssignmentDisposable();
watchStatusChanged.Disposable = this.ObserveStatusChanged().Subscribe(x =>
{
if (x == StatusCode.ExceptionOnConnect)
{
watchStatusChanged.Dispose();
future.OnError(new ConnectionFailedException(serverAddress, applicationName));
}
if (x == StatusCode.Connect)
{
watchStatusChanged.Dispose();
future.OnNext(true);
future.OnCompleted();
}
});
if (this.Connect(serverAddress, applicationName))
{
this.LastConnectServerAddress = serverAddress;
this.LastConnectApplicationName = applicationName;
return future.Timeout(Timeout).Catch((Exception ex) =>
{
watchStatusChanged.Dispose();
this.Disconnect();
return Observable.Throw<bool>(ex);
});
}
else
{
watchStatusChanged.Dispose();
return Observable.Return(false);
}
}