fix: scope borrow in heat seeking to try to prevent deadlock
This commit is contained in:
@@ -30,48 +30,53 @@ pub async fn heat_seek(state: State) {
|
||||
let mut vcs_in_guild_senders = BTreeMap::default();
|
||||
|
||||
loop {
|
||||
for (&guild_id, vcs_in_guild) in &*vcs_watcher.borrow() {
|
||||
let vcs_in_guild_sender = vcs_in_guild_senders.entry(guild_id).or_insert_with(|| {
|
||||
let (vcs_in_guild_sender, vcs_in_guild_watcher) =
|
||||
watch::channel(Default::default());
|
||||
let (channel_heat_sender, channel_heat_watcher) =
|
||||
watch::channel(Default::default());
|
||||
let (heat_map_sender, heat_map_watcher) = watch::channel(Default::default());
|
||||
let (hottest_vc_sender, hottest_vc_watcher) = watch::channel(Default::default());
|
||||
{
|
||||
for (&guild_id, vcs_in_guild) in &*vcs_watcher.borrow() {
|
||||
let vcs_in_guild_sender =
|
||||
vcs_in_guild_senders.entry(guild_id).or_insert_with(|| {
|
||||
let (vcs_in_guild_sender, vcs_in_guild_watcher) =
|
||||
watch::channel(Default::default());
|
||||
let (channel_heat_sender, channel_heat_watcher) =
|
||||
watch::channel(Default::default());
|
||||
let (heat_map_sender, heat_map_watcher) =
|
||||
watch::channel(Default::default());
|
||||
let (hottest_vc_sender, hottest_vc_watcher) =
|
||||
watch::channel(Default::default());
|
||||
|
||||
tokio::spawn(
|
||||
evaluate_heat()
|
||||
.bot_manager(state.bot_manager.clone())
|
||||
.bot_owner_user_id(state.discord_bot_owner_user_id)
|
||||
.bot_user_id(state.discord_user_id)
|
||||
.cancellation_token(state.cancellation_token.clone())
|
||||
.channel_heat_sender(channel_heat_sender)
|
||||
.vcs_in_guild_watcher(vcs_in_guild_watcher)
|
||||
.call(),
|
||||
);
|
||||
tokio::spawn(
|
||||
map_heat()
|
||||
.cancellation_token(state.cancellation_token.clone())
|
||||
.channel_heat_watcher(channel_heat_watcher)
|
||||
.heat_map_sender(heat_map_sender)
|
||||
.call(),
|
||||
);
|
||||
tokio::spawn(
|
||||
track_hottest_vc()
|
||||
.cancellation_token(state.cancellation_token.clone())
|
||||
.heat_map_watcher(heat_map_watcher)
|
||||
.hottest_vc_sender(hottest_vc_sender)
|
||||
.call(),
|
||||
);
|
||||
tokio::spawn(follow_hottest_vc(
|
||||
state.clone(),
|
||||
guild_id,
|
||||
hottest_vc_watcher,
|
||||
));
|
||||
tokio::spawn(
|
||||
evaluate_heat()
|
||||
.bot_manager(state.bot_manager.clone())
|
||||
.bot_owner_user_id(state.discord_bot_owner_user_id)
|
||||
.bot_user_id(state.discord_user_id)
|
||||
.cancellation_token(state.cancellation_token.clone())
|
||||
.channel_heat_sender(channel_heat_sender)
|
||||
.vcs_in_guild_watcher(vcs_in_guild_watcher)
|
||||
.call(),
|
||||
);
|
||||
tokio::spawn(
|
||||
map_heat()
|
||||
.cancellation_token(state.cancellation_token.clone())
|
||||
.channel_heat_watcher(channel_heat_watcher)
|
||||
.heat_map_sender(heat_map_sender)
|
||||
.call(),
|
||||
);
|
||||
tokio::spawn(
|
||||
track_hottest_vc()
|
||||
.cancellation_token(state.cancellation_token.clone())
|
||||
.heat_map_watcher(heat_map_watcher)
|
||||
.hottest_vc_sender(hottest_vc_sender)
|
||||
.call(),
|
||||
);
|
||||
tokio::spawn(follow_hottest_vc(
|
||||
state.clone(),
|
||||
guild_id,
|
||||
hottest_vc_watcher,
|
||||
));
|
||||
|
||||
vcs_in_guild_sender
|
||||
});
|
||||
vcs_in_guild_sender.send_replace(Arc::new(vcs_in_guild.clone()));
|
||||
vcs_in_guild_sender
|
||||
});
|
||||
vcs_in_guild_sender.send_replace(Arc::new(vcs_in_guild.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
if matches!(
|
||||
|
||||
Reference in New Issue
Block a user