Skip to content

Commit

Permalink
ConfigureAwait
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Nov 25, 2024
1 parent 30b6f28 commit bc49433
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions NewLife.MQTT/Clusters/ClusterNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void Init()
{
Init();

return await Client.InvokeAsync<String>("Cluster/Echo", msg);
return await Client.InvokeAsync<String>("Cluster/Echo", msg).ConfigureAwait(false);
}

/// <summary>加入集群</summary>
Expand All @@ -91,7 +91,7 @@ private void Init()

_myNode = info;

return _remoteNode = await Client.InvokeAsync<NodeInfo>("Cluster/Join", info);
return _remoteNode = await Client.InvokeAsync<NodeInfo>("Cluster/Join", info).ConfigureAwait(false);
}

/// <summary>心跳</summary>
Expand All @@ -104,15 +104,15 @@ private void Init()
if (_remoteNode == null)
return await Join(info);
else
return await Client.InvokeAsync<NodeInfo>("Cluster/Ping", info);
return await Client.InvokeAsync<NodeInfo>("Cluster/Ping", info).ConfigureAwait(false);
}

/// <summary>离开集群</summary>
public async Task<String?> Leave(NodeInfo info)
{
Init();

return await Client.InvokeAsync<String>("Cluster/Leave", info);
return await Client.InvokeAsync<String>("Cluster/Leave", info).ConfigureAwait(false);
}

/// <summary>订阅</summary>
Expand All @@ -122,7 +122,7 @@ private void Init()
{
Init();

return await Client.InvokeAsync<String>("Cluster/Subscribe", infos);
return await Client.InvokeAsync<String>("Cluster/Subscribe", infos).ConfigureAwait(false);
}

/// <summary>退订</summary>
Expand All @@ -132,7 +132,7 @@ private void Init()
{
Init();

return await Client.InvokeAsync<String>("Cluster/Unsubscribe", infos);
return await Client.InvokeAsync<String>("Cluster/Unsubscribe", infos).ConfigureAwait(false);
}

/// <summary>心跳</summary>
Expand All @@ -141,15 +141,15 @@ private void Init()
{
Init();

return await Client.InvokeAsync<String>("Cluster/Ping");
return await Client.InvokeAsync<String>("Cluster/Ping").ConfigureAwait(false);
}

/// <summary>发布</summary>
public async Task<String?> Publish(PublishInfo info)
{
Init();

return await Client.InvokeAsync<String>("Cluster/Publish", info);
return await Client.InvokeAsync<String>("Cluster/Publish", info).ConfigureAwait(false);
}
#endregion
}
6 changes: 3 additions & 3 deletions NewLife.MQTT/Handlers/IMqttHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ protected virtual UnsubAck OnUnsubscribe(UnsubscribeMessage message)
{
if (message == null) throw new ArgumentNullException(nameof(message));

var rs = (await SendAsync(message, message.QoS != QualityOfService.AtMostOnce)) as MqttIdMessage;
var rs = (await SendAsync(message, message.QoS != QualityOfService.AtMostOnce).ConfigureAwait(false)) as MqttIdMessage;

if (rs is PubRec)
{
var rel = new PubRel();
var cmp = (await SendAsync(rel, true)) as PubComp;
var cmp = (await SendAsync(rel, true).ConfigureAwait(false)) as PubComp;
return cmp;
}

Expand Down Expand Up @@ -287,7 +287,7 @@ protected virtual UnsubAck OnUnsubscribe(UnsubscribeMessage message)
return null;
}

var rs = await client.SendMessageAsync(msg);
var rs = await client.SendMessageAsync(msg).ConfigureAwait(false);

if (Log != null && Log.Level <= LogLevel.Debug) WriteLog("<= {0}", rs as MqttMessage);

Expand Down
12 changes: 6 additions & 6 deletions NewLife.MQTT/MqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void Init()
return null;
}

var rs = await client.SendMessageAsync(msg);
var rs = await client.SendMessageAsync(msg).ConfigureAwait(false);

// 重置
_taskCanceledCount = 0;
Expand Down Expand Up @@ -391,7 +391,7 @@ public async Task<ConnAck> ConnectAsync(ConnectMessage message)
// 心跳
if (KeepAlive > 0 && message.KeepAliveInSeconds == 0) message.KeepAliveInSeconds = (UInt16)KeepAlive;

var rs = (await SendAsync(message)) as ConnAck;
var rs = (await SendAsync(message).ConfigureAwait(false)) as ConnAck;

// 判断响应,是否成功连接
if (rs!.ReturnCode != ConnectReturnCode.Accepted)
Expand All @@ -414,7 +414,7 @@ public async Task<ConnAck> ConnectAsync(ConnectMessage message)
Requests = _subs.Values.ToArray(),
};

var rs2 = (await SendAsync(message2)) as SubAck;
var rs2 = (await SendAsync(message2).ConfigureAwait(false)) as SubAck;
if (rs2 == null) _subs.Clear();
}

Expand All @@ -427,7 +427,7 @@ public async Task DisconnectAsync()
{
var message = new DisconnectMessage();

await SendAsync(message, false);
await SendAsync(message, false).ConfigureAwait(false);

var e = new EventArgs();
Disconnected?.Invoke(this, e);
Expand Down Expand Up @@ -481,12 +481,12 @@ private void Client_Closed(Object sender, EventArgs e)
{
if (message == null) throw new ArgumentNullException(nameof(message));

var rs = (await SendAsync(message, message.QoS != QualityOfService.AtMostOnce)) as MqttIdMessage;
var rs = (await SendAsync(message, message.QoS != QualityOfService.AtMostOnce).ConfigureAwait(false)) as MqttIdMessage;

if (rs is PubRec)
{
var rel = new PubRel();
var cmp = (await SendAsync(rel, true)) as PubComp;
var cmp = (await SendAsync(rel, true).ConfigureAwait(false)) as PubComp;
return cmp;
}

Expand Down

0 comments on commit bc49433

Please sign in to comment.