/// <summary> /// Creates a new <see cref="QuicConnection"/> and connects it to the peer. /// </summary> /// <param name="options">Options for the connection.</param> /// <param name="cancellationToken">A cancellation token that can be used to cancel the asynchronous operation.</param> /// <returns>An asynchronous task that completes with the connected connection.</returns> public static async ValueTask <QuicConnection> ConnectAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken = default) { if (!IsSupported) { throw new PlatformNotSupportedException(SR.SystemNetQuic_PlatformNotSupported); } // Validate and fill in defaults for the options. options.Validate(nameof(options)); QuicConnection connection = new QuicConnection(); try { await connection.FinishConnectAsync(options, cancellationToken).ConfigureAwait(false); } catch { await connection.DisposeAsync().ConfigureAwait(false); throw; } return(connection); }