Skip to content

Commit be52e79

Browse files
committed
Use Task.WaitAsync() to replace TaskUtils.TaskWait()
1 parent 55b2f90 commit be52e79

File tree

4 files changed

+24
-47
lines changed

4 files changed

+24
-47
lines changed

Quick.Protocol.Tcp/QpTcpClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ protected override async Task<Stream> InnerConnectAsync()
3636
var connectTask = tcpClient.ConnectAsync(Dns.GetHostAddresses(options.Host), options.Port, cts.Token).AsTask();
3737
try
3838
{
39-
await TaskUtils.TaskWait(connectTask, options.ConnectionTimeout)
39+
await connectTask
40+
.WaitAsync(TimeSpan.FromMilliseconds(options.ConnectionTimeout))
4041
.ConfigureAwait(false);
4142
}
4243
catch

Quick.Protocol.Udp/QpUdpClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ protected override async Task<Stream> InnerConnectAsync()
3131
udpAsTcpClient = new UdpAsTcpClient();
3232
else
3333
udpAsTcpClient = new UdpAsTcpClient(new IPEndPoint(IPAddress.Parse(options.LocalHost), options.LocalPort));
34-
await TaskUtils.TaskWait(Task.Run(() => udpAsTcpClient.Connect(options.Host, options.Port)), options.ConnectionTimeout).ConfigureAwait(false);
34+
await Task.Run(() => udpAsTcpClient.Connect(options.Host, options.Port))
35+
.WaitAsync(TimeSpan.FromMilliseconds(options.ConnectionTimeout))
36+
.ConfigureAwait(false);
3537

3638
if (!udpAsTcpClient.Connected)
3739
throw new IOException($"Failed to connect to {options.Host}:{options.Port}.");

Quick.Protocol/QpChannel.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ await gzStream.WriteAsync(packageBuffer.Array, packageBuffer.Offset + PACKAGE_TO
335335

336336
//发送包内容
337337
var writeTask = stream.WriteAsync(packageBuffer.Array, packageBuffer.Offset, packageBuffer.Count);
338-
await await TaskUtils.TaskWait(writeTask, options.InternalTransportTimeout).ConfigureAwait(false);
338+
await writeTask
339+
.WaitAsync(TimeSpan.FromMilliseconds(options.InternalTransportTimeout))
340+
.ConfigureAwait(false);
339341

340342
if (writeTask.IsCanceled)
341343
return;
@@ -645,7 +647,10 @@ private async Task<int> readData(Stream stream, byte[] buffer, int startIndex, i
645647
if (cancellationToken.IsCancellationRequested)
646648
break;
647649
var readTask = stream.ReadAsync(buffer, count + startIndex, totalCount - count, cancellationToken);
648-
ret = await await TaskUtils.TaskWait(readTask, options.InternalTransportTimeout).ConfigureAwait(false);
650+
ret = await readTask
651+
.WaitAsync(TimeSpan.FromMilliseconds(options.InternalTransportTimeout))
652+
.ConfigureAwait(false);
653+
649654
if (readTask.IsCanceled || ret == 0)
650655
break;
651656
if (ret < 0)
@@ -1127,7 +1132,9 @@ public async Task<CommandResponseTypeNameAndContent> SendCommand(string requestT
11271132
{
11281133
try
11291134
{
1130-
await TaskUtils.TaskWait(Task.Run(() => SendCommandRequestPackage(commandContext.Id, requestTypeName, requestContent, afterSendHandler)), timeout).ConfigureAwait(false);
1135+
await Task.Run(() => SendCommandRequestPackage(commandContext.Id, requestTypeName, requestContent, afterSendHandler))
1136+
.WaitAsync(TimeSpan.FromMilliseconds(timeout))
1137+
.ConfigureAwait(false);
11311138
}
11321139
catch
11331140
{
@@ -1140,7 +1147,9 @@ public async Task<CommandResponseTypeNameAndContent> SendCommand(string requestT
11401147
commandDict.TryRemove(commandContext.Id, out _);
11411148
}
11421149
}
1143-
return await await TaskUtils.TaskWait(commandContext.ResponseTask, timeout).ConfigureAwait(false);
1150+
return await commandContext.ResponseTask
1151+
.WaitAsync(TimeSpan.FromMilliseconds(timeout))
1152+
.ConfigureAwait(false);
11441153
}
11451154
}
11461155

@@ -1164,7 +1173,9 @@ public async Task<TCmdResponse> SendCommand<TCmdResponse>(IQpCommandRequest<TCmd
11641173
{
11651174
try
11661175
{
1167-
await TaskUtils.TaskWait(Task.Run(() => SendCommandRequestPackage(commandContext.Id, typeName, requestContent, afterSendHandler)), timeout).ConfigureAwait(false);
1176+
await Task.Run(() => SendCommandRequestPackage(commandContext.Id, typeName, requestContent, afterSendHandler))
1177+
.WaitAsync(TimeSpan.FromMilliseconds(timeout))
1178+
.ConfigureAwait(false);
11681179
}
11691180
catch
11701181
{
@@ -1177,7 +1188,9 @@ public async Task<TCmdResponse> SendCommand<TCmdResponse>(IQpCommandRequest<TCmd
11771188
commandDict.TryRemove(commandContext.Id, out _);
11781189
}
11791190
}
1180-
ret = await await TaskUtils.TaskWait(commandContext.ResponseTask, timeout).ConfigureAwait(false);
1191+
ret = await commandContext.ResponseTask
1192+
.WaitAsync(TimeSpan.FromMilliseconds(timeout))
1193+
.ConfigureAwait(false);
11811194
}
11821195
return JsonConvert.DeserializeObject<TCmdResponse>(ret.Content);
11831196
}

Quick.Protocol/Utils/TaskUtils.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)