18
18
// </copyright>
19
19
20
20
using System ;
21
+ using System . Threading ;
21
22
using System . Threading . Tasks ;
22
23
using OpenQA . Selenium . BiDi . Communication ;
23
24
@@ -38,7 +39,7 @@ public class BiDi : IAsyncDisposable
38
39
39
40
private readonly object _moduleLock = new ( ) ;
40
41
41
- internal BiDi ( string url )
42
+ private BiDi ( string url )
42
43
{
43
44
var uri = new Uri ( url ) ;
44
45
@@ -49,15 +50,10 @@ internal Session.SessionModule SessionModule
49
50
{
50
51
get
51
52
{
52
- if ( _sessionModule is null )
53
+ if ( _sessionModule is not null ) return _sessionModule ;
54
+ lock ( _moduleLock )
53
55
{
54
- lock ( _moduleLock )
55
- {
56
- if ( _sessionModule is null )
57
- {
58
- _sessionModule = new Session . SessionModule ( _broker ) ;
59
- }
60
- }
56
+ _sessionModule ??= new Session . SessionModule ( _broker ) ;
61
57
}
62
58
return _sessionModule ;
63
59
}
@@ -67,15 +63,10 @@ public BrowsingContext.BrowsingContextModule BrowsingContext
67
63
{
68
64
get
69
65
{
70
- if ( _browsingContextModule is null )
66
+ if ( _browsingContextModule is not null ) return _browsingContextModule ;
67
+ lock ( _moduleLock )
71
68
{
72
- lock ( _moduleLock )
73
- {
74
- if ( _browsingContextModule is null )
75
- {
76
- _browsingContextModule = new BrowsingContext . BrowsingContextModule ( _broker ) ;
77
- }
78
- }
69
+ _browsingContextModule ??= new BrowsingContext . BrowsingContextModule ( _broker ) ;
79
70
}
80
71
return _browsingContextModule ;
81
72
}
@@ -85,15 +76,10 @@ public Browser.BrowserModule Browser
85
76
{
86
77
get
87
78
{
88
- if ( _browserModule is null )
79
+ if ( _browserModule is not null ) return _browserModule ;
80
+ lock ( _moduleLock )
89
81
{
90
- lock ( _moduleLock )
91
- {
92
- if ( _browserModule is null )
93
- {
94
- _browserModule = new Browser . BrowserModule ( _broker ) ;
95
- }
96
- }
82
+ _browserModule ??= new Browser . BrowserModule ( _broker ) ;
97
83
}
98
84
return _browserModule ;
99
85
}
@@ -103,15 +89,10 @@ public Network.NetworkModule Network
103
89
{
104
90
get
105
91
{
106
- if ( _networkModule is null )
92
+ if ( _networkModule is not null ) return _networkModule ;
93
+ lock ( _moduleLock )
107
94
{
108
- lock ( _moduleLock )
109
- {
110
- if ( _networkModule is null )
111
- {
112
- _networkModule = new Network . NetworkModule ( _broker ) ;
113
- }
114
- }
95
+ _networkModule ??= new Network . NetworkModule ( _broker ) ;
115
96
}
116
97
return _networkModule ;
117
98
}
@@ -121,15 +102,10 @@ internal Input.InputModule InputModule
121
102
{
122
103
get
123
104
{
124
- if ( _inputModule is null )
105
+ if ( _inputModule is not null ) return _inputModule ;
106
+ lock ( _moduleLock )
125
107
{
126
- lock ( _moduleLock )
127
- {
128
- if ( _inputModule is null )
129
- {
130
- _inputModule = new Input . InputModule ( _broker ) ;
131
- }
132
- }
108
+ _inputModule ??= new Input . InputModule ( _broker ) ;
133
109
}
134
110
return _inputModule ;
135
111
}
@@ -139,15 +115,10 @@ public Script.ScriptModule Script
139
115
{
140
116
get
141
117
{
142
- if ( _scriptModule is null )
118
+ if ( _scriptModule is not null ) return _scriptModule ;
119
+ lock ( _moduleLock )
143
120
{
144
- lock ( _moduleLock )
145
- {
146
- if ( _scriptModule is null )
147
- {
148
- _scriptModule = new Script . ScriptModule ( _broker ) ;
149
- }
150
- }
121
+ _scriptModule ??= new Script . ScriptModule ( _broker ) ;
151
122
}
152
123
return _scriptModule ;
153
124
}
@@ -157,15 +128,10 @@ public Log.LogModule Log
157
128
{
158
129
get
159
130
{
160
- if ( _logModule is null )
131
+ if ( _logModule is not null ) return _logModule ;
132
+ lock ( _moduleLock )
161
133
{
162
- lock ( _moduleLock )
163
- {
164
- if ( _logModule is null )
165
- {
166
- _logModule = new Log . LogModule ( _broker ) ;
167
- }
168
- }
134
+ _logModule ??= new Log . LogModule ( _broker ) ;
169
135
}
170
136
return _logModule ;
171
137
}
@@ -175,15 +141,10 @@ public Storage.StorageModule Storage
175
141
{
176
142
get
177
143
{
178
- if ( _storageModule is null )
144
+ if ( _storageModule is not null ) return _storageModule ;
145
+ lock ( _moduleLock )
179
146
{
180
- lock ( _moduleLock )
181
- {
182
- if ( _storageModule is null )
183
- {
184
- _storageModule = new Storage . StorageModule ( _broker ) ;
185
- }
186
- }
147
+ _storageModule ??= new Storage . StorageModule ( _broker ) ;
187
148
}
188
149
return _storageModule ;
189
150
}
@@ -198,7 +159,7 @@ public static async Task<BiDi> ConnectAsync(string url)
198
159
{
199
160
var bidi = new BiDi ( url ) ;
200
161
201
- await bidi . _broker . ConnectAsync ( default ) . ConfigureAwait ( false ) ;
162
+ await bidi . _broker . ConnectAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
202
163
203
164
return bidi ;
204
165
}
0 commit comments