@@ -87,7 +87,8 @@ internal Connection(string url, int delay, ClientWebSocket ws, ILoggerFactory lo
8787 internal async Task < dynamic > SendAsync ( string method , dynamic args = null )
8888 {
8989 var id = ++ _lastId ;
90- var message = JsonConvert . SerializeObject ( new Dictionary < string , object > ( ) {
90+ var message = JsonConvert . SerializeObject ( new Dictionary < string , object >
91+ {
9192 { "id" , id } ,
9293 { "method" , method } ,
9394 { "params" , args }
@@ -102,7 +103,7 @@ internal async Task<dynamic> SendAsync(string method, dynamic args = null)
102103 } ;
103104
104105 var encoded = Encoding . UTF8 . GetBytes ( message ) ;
105- var buffer = new ArraySegment < Byte > ( encoded , 0 , encoded . Length ) ;
106+ var buffer = new ArraySegment < byte > ( encoded , 0 , encoded . Length ) ;
106107 await _socketQueue . Enqueue ( ( ) => WebSocket . SendAsync ( buffer , WebSocketMessageType . Text , true , default ( CancellationToken ) ) ) ;
107108
108109 if ( method == CloseMessage )
@@ -169,7 +170,7 @@ private async Task<object> GetResponseAsync()
169170 }
170171
171172 var endOfMessage = false ;
172- string response = string . Empty ;
173+ var response = string . Empty ;
173174
174175 while ( ! endOfMessage )
175176 {
@@ -212,6 +213,11 @@ private async Task<object> GetResponseAsync()
212213
213214 if ( ! string . IsNullOrEmpty ( response ) )
214215 {
216+ if ( Delay > 0 )
217+ {
218+ await Task . Delay ( Delay ) ;
219+ }
220+
215221 ProcessResponse ( response ) ;
216222 }
217223 }
@@ -226,7 +232,7 @@ private void ProcessResponse(string response)
226232
227233 if ( objAsJObject [ "id" ] != null )
228234 {
229- int id = ( int ) objAsJObject [ "id" ] ;
235+ var id = ( int ) objAsJObject [ "id" ] ;
230236
231237 //If we get the object we are waiting for we return if
232238 //if not we add this to the list, sooner or later some one will come for it
@@ -294,4 +300,4 @@ public void Dispose()
294300
295301 #endregion
296302 }
297- }
303+ }
0 commit comments