Reduce lock time on session create, better disconnect checking in IPC loop
parent
ff0e79d1af
commit
edf93c693e
|
@ -52,16 +52,10 @@ impl InnerSessionManager {
|
||||||
/// Creates a new session for the given user in the given guild.
|
/// Creates a new session for the given user in the given guild.
|
||||||
pub async fn create_session(
|
pub async fn create_session(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Context,
|
session: SpoticordSession,
|
||||||
guild_id: GuildId,
|
guild_id: GuildId,
|
||||||
channel_id: ChannelId,
|
|
||||||
text_channel_id: ChannelId,
|
|
||||||
owner_id: UserId,
|
owner_id: UserId,
|
||||||
) -> Result<(), SessionCreateError> {
|
) -> Result<(), SessionCreateError> {
|
||||||
// Create session first to make sure locks are kept for as little time as possible
|
|
||||||
let session =
|
|
||||||
SpoticordSession::new(ctx, guild_id, channel_id, text_channel_id, owner_id).await?;
|
|
||||||
|
|
||||||
self.sessions.insert(guild_id, session);
|
self.sessions.insert(guild_id, session);
|
||||||
self.owner_map.insert(owner_id, guild_id);
|
self.owner_map.insert(owner_id, guild_id);
|
||||||
|
|
||||||
|
@ -139,11 +133,15 @@ impl SessionManager {
|
||||||
text_channel_id: ChannelId,
|
text_channel_id: ChannelId,
|
||||||
owner_id: UserId,
|
owner_id: UserId,
|
||||||
) -> Result<(), SessionCreateError> {
|
) -> Result<(), SessionCreateError> {
|
||||||
|
// Create session first to make sure locks are kept for as little time as possible
|
||||||
|
let session =
|
||||||
|
SpoticordSession::new(ctx, guild_id, channel_id, text_channel_id, owner_id).await?;
|
||||||
|
|
||||||
self
|
self
|
||||||
.0
|
.0
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.create_session(ctx, guild_id, channel_id, text_channel_id, owner_id)
|
.create_session(session, guild_id, owner_id)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,6 +255,14 @@ impl SpoticordSession {
|
||||||
// Required for IpcPacket::TrackChange to work
|
// Required for IpcPacket::TrackChange to work
|
||||||
tokio::task::yield_now().await;
|
tokio::task::yield_now().await;
|
||||||
|
|
||||||
|
// Check if the session has been disconnected
|
||||||
|
if {
|
||||||
|
let inner = inner.read().await;
|
||||||
|
inner.disconnected
|
||||||
|
} {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
let msg = match client.try_recv() {
|
let msg = match client.try_recv() {
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
Err(why) => {
|
Err(why) => {
|
||||||
|
|
Loading…
Reference in New Issue