@@ -59,11 +59,10 @@ public static Task CloseAsync(this IConnection connection, ushort reasonCode, st
5959 /// To wait infinitely for the close operations to complete use <see cref="System.Threading.Timeout.InfiniteTimeSpan"/>.
6060 /// </para>
6161 /// </remarks>
62- public static async Task CloseAsync ( this IConnection connection , TimeSpan timeout )
62+ public static Task CloseAsync ( this IConnection connection , TimeSpan timeout )
6363 {
64- using var cts = new CancellationTokenSource ( timeout ) ;
65- await connection . CloseAsync ( Constants . ReplySuccess , "Goodbye" , timeout , false , cts . Token )
66- . ConfigureAwait ( false ) ;
64+ return connection . CloseAsync ( Constants . ReplySuccess , "Goodbye" , timeout , false ,
65+ CancellationToken . None ) ;
6766 }
6867
6968 /// <summary>
@@ -83,11 +82,10 @@ await connection.CloseAsync(Constants.ReplySuccess, "Goodbye", timeout, false, c
8382 /// Operation timeout.
8483 /// </para>
8584 /// </remarks>
86- public static async Task CloseAsync ( this IConnection connection , ushort reasonCode , string reasonText , TimeSpan timeout )
85+ public static Task CloseAsync ( this IConnection connection , ushort reasonCode , string reasonText , TimeSpan timeout )
8786 {
88- using var cts = new CancellationTokenSource ( timeout ) ;
89- await connection . CloseAsync ( reasonCode , reasonText , timeout , false , cts . Token )
90- . ConfigureAwait ( false ) ;
87+ return connection . CloseAsync ( reasonCode , reasonText , timeout , false ,
88+ CancellationToken . None ) ;
9189 }
9290
9391 /// <summary>
@@ -99,12 +97,10 @@ await connection.CloseAsync(reasonCode, reasonText, timeout, false, cts.Token)
9997 /// <see cref="IOException"/> during closing connection.
10098 ///This method waits infinitely for the in-progress close operation to complete.
10199 /// </remarks>
102- public static async Task AbortAsync ( this IConnection connection )
100+ public static Task AbortAsync ( this IConnection connection )
103101 {
104- using var cts = new CancellationTokenSource ( InternalConstants . DefaultConnectionAbortTimeout ) ;
105- await connection . CloseAsync ( Constants . ReplySuccess ,
106- "Connection close forced" , InternalConstants . DefaultConnectionAbortTimeout , true , cts . Token )
107- . ConfigureAwait ( false ) ;
102+ return connection . CloseAsync ( Constants . ReplySuccess , "Connection close forced" , InternalConstants . DefaultConnectionAbortTimeout , true ,
103+ CancellationToken . None ) ;
108104 }
109105
110106 /// <summary>
@@ -120,12 +116,10 @@ await connection.CloseAsync(Constants.ReplySuccess,
120116 /// A message indicating the reason for closing the connection
121117 /// </para>
122118 /// </remarks>
123- public static async Task AbortAsync ( this IConnection connection , ushort reasonCode , string reasonText )
119+ public static Task AbortAsync ( this IConnection connection , ushort reasonCode , string reasonText )
124120 {
125- using var cts = new CancellationTokenSource ( InternalConstants . DefaultConnectionAbortTimeout ) ;
126- await connection . CloseAsync ( reasonCode ,
127- reasonText , InternalConstants . DefaultConnectionAbortTimeout , true , cts . Token )
128- . ConfigureAwait ( false ) ;
121+ return connection . CloseAsync ( reasonCode , reasonText , InternalConstants . DefaultConnectionAbortTimeout , true ,
122+ CancellationToken . None ) ;
129123 }
130124
131125 /// <summary>
@@ -141,12 +135,10 @@ await connection.CloseAsync(reasonCode,
141135 /// To wait infinitely for the close operations to complete use <see cref="Timeout.Infinite"/>.
142136 /// </para>
143137 /// </remarks>
144- public static async Task AbortAsync ( this IConnection connection , TimeSpan timeout )
138+ public static Task AbortAsync ( this IConnection connection , TimeSpan timeout )
145139 {
146- using var cts = new CancellationTokenSource ( InternalConstants . DefaultConnectionAbortTimeout ) ;
147- await connection . CloseAsync ( Constants . ReplySuccess ,
148- "Connection close forced" , timeout , true , cts . Token )
149- . ConfigureAwait ( false ) ;
140+ return connection . CloseAsync ( Constants . ReplySuccess , "Connection close forced" , timeout , true ,
141+ CancellationToken . None ) ;
150142 }
151143
152144 /// <summary>
@@ -163,12 +155,10 @@ await connection.CloseAsync(Constants.ReplySuccess,
163155 /// A message indicating the reason for closing the connection.
164156 /// </para>
165157 /// </remarks>
166- public static async Task AbortAsync ( this IConnection connection , ushort reasonCode , string reasonText , TimeSpan timeout )
158+ public static Task AbortAsync ( this IConnection connection , ushort reasonCode , string reasonText , TimeSpan timeout )
167159 {
168- using var cts = new CancellationTokenSource ( InternalConstants . DefaultConnectionAbortTimeout ) ;
169- await connection . CloseAsync ( reasonCode ,
170- reasonText , timeout , true , cts . Token )
171- . ConfigureAwait ( false ) ;
160+ return connection . CloseAsync ( reasonCode , reasonText , timeout , true ,
161+ CancellationToken . None ) ;
172162 }
173163 }
174164}
0 commit comments