File tree Expand file tree Collapse file tree 2 files changed +18
-9
lines changed
dotnet/src/webdriver/BiDi Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change 2020using System ;
2121using System . Threading . Tasks ;
2222using OpenQA . Selenium . BiDi . Communication ;
23- using OpenQA . Selenium . BiDi . Communication . Transport ;
2423
2524namespace OpenQA . Selenium . BiDi ;
2625
2726public class BiDi : IAsyncDisposable
2827{
29- private readonly ITransport _transport ;
3028 private readonly Broker _broker ;
3129
3230 private readonly Lazy < Modules . Session . SessionModule > _sessionModule ;
@@ -42,8 +40,7 @@ internal BiDi(string url)
4240 {
4341 var uri = new Uri ( url ) ;
4442
45- _transport = new WebSocketTransport ( new Uri ( url ) ) ;
46- _broker = new Broker ( this , _transport ) ;
43+ _broker = new Broker ( this , uri ) ;
4744
4845 _sessionModule = new Lazy < Modules . Session . SessionModule > ( ( ) => new Modules . Session . SessionModule ( _broker ) ) ;
4946 _browsingContextModule = new Lazy < Modules . BrowsingContext . BrowsingContextModule > ( ( ) => new Modules . BrowsingContext . BrowsingContextModule ( _broker ) ) ;
@@ -83,10 +80,14 @@ public Task EndAsync(Modules.Session.EndOptions? options = null)
8380 return SessionModule . EndAsync ( options ) ;
8481 }
8582
86- public async ValueTask DisposeAsync ( )
83+ public virtual async ValueTask DisposeAsyncCore ( )
8784 {
8885 await _broker . DisposeAsync ( ) . ConfigureAwait ( false ) ;
86+ }
8987
90- _transport ? . Dispose ( ) ;
88+ public async ValueTask DisposeAsync ( )
89+ {
90+ await DisposeAsyncCore ( ) ;
91+ GC . SuppressFinalize ( this ) ;
9192 }
9293}
Original file line number Diff line number Diff line change @@ -54,10 +54,10 @@ public class Broker : IAsyncDisposable
5454
5555 private readonly BiDiJsonSerializerContext _jsonSerializerContext ;
5656
57- internal Broker ( BiDi bidi , ITransport transport )
57+ internal Broker ( BiDi bidi , Uri url )
5858 {
5959 _bidi = bidi ;
60- _transport = transport ;
60+ _transport = new WebSocketTransport ( url ) ;
6161
6262 var jsonSerializerOptions = new JsonSerializerOptions
6363 {
@@ -298,7 +298,7 @@ public async Task UnsubscribeAsync(Modules.Session.Subscription subscription, Ev
298298 }
299299 }
300300
301- public async ValueTask DisposeAsync ( )
301+ public virtual async ValueTask DisposeAsyncCore ( )
302302 {
303303 _pendingEvents . CompleteAdding ( ) ;
304304
@@ -308,5 +308,13 @@ public async ValueTask DisposeAsync()
308308 {
309309 await _eventEmitterTask . ConfigureAwait ( false ) ;
310310 }
311+
312+ _transport . Dispose ( ) ;
313+ }
314+
315+ public async ValueTask DisposeAsync ( )
316+ {
317+ await DisposeAsyncCore ( ) ;
318+ GC . SuppressFinalize ( this ) ;
311319 }
312320}
You can’t perform that action at this time.
0 commit comments