public static async Task <TResult> ExecuteAsync <TResult>( this IWriteOperation <TResult> operation, IConnectionSourceHandle connectionSource, TimeSpan timeout, CancellationToken cancellationToken) { Ensure.IsNotNull(operation, "operation"); using (var writeBinding = new ConnectionSourceReadWriteBinding(connectionSource.Fork(), ReadPreference.Primary)) { return(await operation.ExecuteAsync(writeBinding, timeout, cancellationToken).ConfigureAwait(false)); } }
/// <summary> /// Checks whether the server is alive (throws an exception if not). /// </summary> public void Ping() { var messageEncoderSettings = GetMessageEncoderSettings(); var operation = new PingOperation(messageEncoderSettings); var server = GetServer(); using (var connectionSource = new ConnectionSourceHandle(new ServerConnectionSource(server))) using (var connectionSourceBinding = new ConnectionSourceReadWriteBinding(connectionSource, ReadPreference.PrimaryPreferred)) { operation.Execute(connectionSourceBinding, _settings.ConnectTimeout, CancellationToken.None); } }