File tree 2 files changed +18
-9
lines changed
dotnet/src/webdriver/BiDi
2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change 20
20
using System ;
21
21
using System . Threading . Tasks ;
22
22
using OpenQA . Selenium . BiDi . Communication ;
23
- using OpenQA . Selenium . BiDi . Communication . Transport ;
24
23
25
24
namespace OpenQA . Selenium . BiDi ;
26
25
27
26
public class BiDi : IAsyncDisposable
28
27
{
29
- private readonly ITransport _transport ;
30
28
private readonly Broker _broker ;
31
29
32
30
private readonly Lazy < Modules . Session . SessionModule > _sessionModule ;
@@ -42,8 +40,7 @@ internal BiDi(string url)
42
40
{
43
41
var uri = new Uri ( url ) ;
44
42
45
- _transport = new WebSocketTransport ( new Uri ( url ) ) ;
46
- _broker = new Broker ( this , _transport ) ;
43
+ _broker = new Broker ( this , uri ) ;
47
44
48
45
_sessionModule = new Lazy < Modules . Session . SessionModule > ( ( ) => new Modules . Session . SessionModule ( _broker ) ) ;
49
46
_browsingContextModule = new Lazy < Modules . BrowsingContext . BrowsingContextModule > ( ( ) => new Modules . BrowsingContext . BrowsingContextModule ( _broker ) ) ;
@@ -83,10 +80,14 @@ public Task EndAsync(Modules.Session.EndOptions? options = null)
83
80
return SessionModule . EndAsync ( options ) ;
84
81
}
85
82
86
- public async ValueTask DisposeAsync ( )
83
+ public virtual async ValueTask DisposeAsyncCore ( )
87
84
{
88
85
await _broker . DisposeAsync ( ) . ConfigureAwait ( false ) ;
86
+ }
89
87
90
- _transport ? . Dispose ( ) ;
88
+ public async ValueTask DisposeAsync ( )
89
+ {
90
+ await DisposeAsyncCore ( ) ;
91
+ GC . SuppressFinalize ( this ) ;
91
92
}
92
93
}
Original file line number Diff line number Diff line change @@ -54,10 +54,10 @@ public class Broker : IAsyncDisposable
54
54
55
55
private readonly BiDiJsonSerializerContext _jsonSerializerContext ;
56
56
57
- internal Broker ( BiDi bidi , ITransport transport )
57
+ internal Broker ( BiDi bidi , Uri url )
58
58
{
59
59
_bidi = bidi ;
60
- _transport = transport ;
60
+ _transport = new WebSocketTransport ( url ) ;
61
61
62
62
var jsonSerializerOptions = new JsonSerializerOptions
63
63
{
@@ -298,7 +298,7 @@ public async Task UnsubscribeAsync(Modules.Session.Subscription subscription, Ev
298
298
}
299
299
}
300
300
301
- public async ValueTask DisposeAsync ( )
301
+ public virtual async ValueTask DisposeAsyncCore ( )
302
302
{
303
303
_pendingEvents . CompleteAdding ( ) ;
304
304
@@ -308,5 +308,13 @@ public async ValueTask DisposeAsync()
308
308
{
309
309
await _eventEmitterTask . ConfigureAwait ( false ) ;
310
310
}
311
+
312
+ _transport . Dispose ( ) ;
313
+ }
314
+
315
+ public async ValueTask DisposeAsync ( )
316
+ {
317
+ await DisposeAsyncCore ( ) ;
318
+ GC . SuppressFinalize ( this ) ;
311
319
}
312
320
}
You can’t perform that action at this time.
0 commit comments