Method OpenAsync
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
OpenAsync(IDbConnection, bool, CancellationToken)
If the connection derives from DbConnection, this will call OpenAsync(CancellationToken);
otherwise it will call Open().
public static ValueTask OpenAsync(this IDbConnection connection, bool configureAwait = true, CancellationToken cancellationToken = default)
Parameters
connectionIDbConnectionThe connection to transact with.
configureAwaitboolIf true (default) will retain the context after opening.
cancellationTokenCancellationTokenAn cancellation token to cancel opening.
Returns
- ValueTask
A task containing the prior connection state.
OpenAsync<T>(IDbConnectionFactory, Func<IDbConnection, ValueTask<T>>, CancellationToken)
Creates a connection from the factory, asynchronously opens it if needed, invokes the action, and then disposes the connection.
public static ValueTask<T> OpenAsync<T>(this IDbConnectionFactory connectionFactory, Func<IDbConnection, ValueTask<T>> action, CancellationToken cancellationToken = default)
Parameters
connectionFactoryIDbConnectionFactoryThe connection factory to create the connection from.
actionFunc<IDbConnection, ValueTask<T>>The asynchronous action to execute. It receives the connection.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
Type Parameters
TThe type returned from the action.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.
OpenAsync(IDbConnectionFactory, Func<IDbConnection, ValueTask>, CancellationToken)
Creates a connection from the factory, asynchronously opens it if needed, invokes the action, and then disposes the connection.
public static ValueTask OpenAsync(this IDbConnectionFactory connectionFactory, Func<IDbConnection, ValueTask> action, CancellationToken cancellationToken = default)
Parameters
connectionFactoryIDbConnectionFactoryThe connection factory to create the connection from.
actionFunc<IDbConnection, ValueTask>The asynchronous action to execute. It receives the connection.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.
OpenAsync<TConnection, T>(IDbConnectionFactory<TConnection>, Func<TConnection, ValueTask<T>>, CancellationToken)
Creates a connection from the factory, asynchronously opens it if needed, invokes the action, and then disposes the connection.
public static ValueTask<T> OpenAsync<TConnection, T>(this IDbConnectionFactory<TConnection> connectionFactory, Func<TConnection, ValueTask<T>> action, CancellationToken cancellationToken = default) where TConnection : IDbConnection
Parameters
connectionFactoryIDbConnectionFactory<TConnection>The connection factory to create the connection from.
actionFunc<TConnection, ValueTask<T>>The asynchronous action to execute. It receives the connection.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
Type Parameters
TConnectionThe connection type.
TThe type returned from the action.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.
OpenAsync<TConnection>(IDbConnectionFactory<TConnection>, Func<TConnection, ValueTask>, CancellationToken)
Creates a connection from the factory, asynchronously opens it if needed, invokes the action, and then disposes the connection.
public static ValueTask OpenAsync<TConnection>(this IDbConnectionFactory<TConnection> connectionFactory, Func<TConnection, ValueTask> action, CancellationToken cancellationToken = default) where TConnection : IDbConnection
Parameters
connectionFactoryIDbConnectionFactory<TConnection>The connection factory to create the connection from.
actionFunc<TConnection, ValueTask>The asynchronous action to execute. It receives the connection.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
Type Parameters
TConnectionThe connection type.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.
OpenAsync<T>(IDbConnectionPool, Func<IDbConnection, ConnectionState, ValueTask<T>>, CancellationToken)
Asynchronously takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.
public static ValueTask<T> OpenAsync<T>(this IDbConnectionPool connectionPool, Func<IDbConnection, ConnectionState, ValueTask<T>> action, CancellationToken cancellationToken = default)
Parameters
connectionPoolIDbConnectionPoolThe connection pool to take the connection from.
actionFunc<IDbConnection, ConnectionState, ValueTask<T>>The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
Type Parameters
TThe type returned from the action.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool.
Exceptions
- ArgumentNullException
connectionPooloractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.
OpenAsync(IDbConnectionPool, Func<IDbConnection, ConnectionState, ValueTask>, CancellationToken)
Asynchronously takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.
public static ValueTask OpenAsync(this IDbConnectionPool connectionPool, Func<IDbConnection, ConnectionState, ValueTask> action, CancellationToken cancellationToken = default)
Parameters
connectionPoolIDbConnectionPoolThe connection pool to take the connection from.
actionFunc<IDbConnection, ConnectionState, ValueTask>The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool.
Exceptions
- ArgumentNullException
connectionPooloractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.
OpenAsync<TConnection, T>(IDbConnectionPool<TConnection>, Func<TConnection, ConnectionState, ValueTask<T>>, CancellationToken)
Asynchronously takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.
public static ValueTask<T> OpenAsync<TConnection, T>(this IDbConnectionPool<TConnection> connectionPool, Func<TConnection, ConnectionState, ValueTask<T>> action, CancellationToken cancellationToken = default) where TConnection : IDbConnection
Parameters
connectionPoolIDbConnectionPool<TConnection>The connection pool to take the connection from.
actionFunc<TConnection, ConnectionState, ValueTask<T>>The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
Type Parameters
TConnectionThe connection type.
TThe type returned from the action.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool.
Exceptions
- ArgumentNullException
connectionPooloractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.
OpenAsync<TConnection>(IDbConnectionPool<TConnection>, Func<TConnection, ConnectionState, ValueTask>, CancellationToken)
Asynchronously takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.
public static ValueTask OpenAsync<TConnection>(this IDbConnectionPool<TConnection> connectionPool, Func<TConnection, ConnectionState, ValueTask> action, CancellationToken cancellationToken = default) where TConnection : IDbConnection
Parameters
connectionPoolIDbConnectionPool<TConnection>The connection pool to take the connection from.
actionFunc<TConnection, ConnectionState, ValueTask>The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
Type Parameters
TConnectionThe connection type.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool.
Exceptions
- ArgumentNullException
connectionPooloractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.
OpenAsync<TConnection, T>(Func<TConnection>, Func<TConnection, ValueTask<T>>, CancellationToken)
Invokes the function to create a connection, asynchronously opens it if needed, invokes the action, and then disposes the connection.
public static ValueTask<T> OpenAsync<TConnection, T>(this Func<TConnection> connectionFactory, Func<TConnection, ValueTask<T>> action, CancellationToken cancellationToken = default) where TConnection : IDbConnection
Parameters
connectionFactoryFunc<TConnection>The function that creates the connection.
actionFunc<TConnection, ValueTask<T>>The asynchronous action to execute. It receives the connection.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
Type Parameters
TConnectionThe connection type.
TThe type returned from the action.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.
OpenAsync<TConnection>(Func<TConnection>, Func<TConnection, ValueTask>, CancellationToken)
Invokes the function to create a connection, asynchronously opens it if needed, invokes the action, and then disposes the connection.
public static ValueTask OpenAsync<TConnection>(this Func<TConnection> connectionFactory, Func<TConnection, ValueTask> action, CancellationToken cancellationToken = default) where TConnection : IDbConnection
Parameters
connectionFactoryFunc<TConnection>The function that creates the connection.
actionFunc<TConnection, ValueTask>The asynchronous action to execute. It receives the connection.
cancellationTokenCancellationTokenA token that cancels opening the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
Type Parameters
TConnectionThe connection type.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled while the connection was being opened.