[Refactor] Remove some unnecessary async/await (#2739)

* Remove some unnecessary async/await

* More not-so-async stuff

* More not-so-async stuff

* Fix merge issue
This commit is contained in:
Dmitry
2023-11-19 00:29:14 +03:00
committed by GitHub
parent 699554ad11
commit 86655a8157
73 changed files with 1020 additions and 1020 deletions

View File

@@ -55,7 +55,7 @@ namespace Discord.Audio
GuildId = guildId;
_connectionLock = new SemaphoreSlim(1, 1);
_udp = udpSocketProvider();
_udp.ReceivedDatagram += async (data, index, count) =>
_udp.ReceivedDatagram += (data, index, count) =>
{
if (index != 0 || count != data.Length)
{
@@ -63,7 +63,7 @@ namespace Discord.Audio
Buffer.BlockCopy(data, index, newData, 0, count);
data = newData;
}
await _receivedPacketEvent.InvokeAsync(data).ConfigureAwait(false);
return _receivedPacketEvent.InvokeAsync(data);
};
WebSocketClient = webSocketProvider();
@@ -83,10 +83,10 @@ namespace Discord.Audio
}
}
};
WebSocketClient.TextMessage += async text =>
WebSocketClient.TextMessage += text =>
{
var msg = JsonConvert.DeserializeObject<SocketFrame>(text);
await _receivedEvent.InvokeAsync((VoiceOpCode)msg.Operation, msg.Payload).ConfigureAwait(false);
return _receivedEvent.InvokeAsync((VoiceOpCode)msg.Operation, msg.Payload);
};
WebSocketClient.Closed += async ex =>
{
@@ -129,23 +129,23 @@ namespace Discord.Audio
#endregion
#region WebSocket
public async Task SendHeartbeatAsync(RequestOptions options = null)
public Task SendHeartbeatAsync(RequestOptions options = null)
=> SendAsync(VoiceOpCode.Heartbeat, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), options: options);
public Task SendIdentityAsync(ulong userId, string sessionId, string token)
{
await SendAsync(VoiceOpCode.Heartbeat, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), options: options).ConfigureAwait(false);
}
public async Task SendIdentityAsync(ulong userId, string sessionId, string token)
{
await SendAsync(VoiceOpCode.Identify, new IdentifyParams
return SendAsync(VoiceOpCode.Identify, new IdentifyParams
{
GuildId = GuildId,
UserId = userId,
SessionId = sessionId,
Token = token
}).ConfigureAwait(false);
});
}
public async Task SendSelectProtocol(string externalIp, int externalPort)
public Task SendSelectProtocol(string externalIp, int externalPort)
{
await SendAsync(VoiceOpCode.SelectProtocol, new SelectProtocolParams
return SendAsync(VoiceOpCode.SelectProtocol, new SelectProtocolParams
{
Protocol = "udp",
Data = new UdpProtocolInfo
@@ -154,15 +154,16 @@ namespace Discord.Audio
Port = externalPort,
Mode = Mode
}
}).ConfigureAwait(false);
});
}
public async Task SendSetSpeaking(bool value)
public Task SendSetSpeaking(bool value)
{
await SendAsync(VoiceOpCode.Speaking, new SpeakingParams
return SendAsync(VoiceOpCode.Speaking, new SpeakingParams
{
IsSpeaking = value,
Delay = 0
}).ConfigureAwait(false);
});
}
public async Task ConnectAsync(string url)
@@ -174,6 +175,7 @@ namespace Discord.Audio
}
finally { _connectionLock.Release(); }
}
private async Task ConnectInternalAsync(string url)
{
ConnectionState = ConnectionState.Connecting;