mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
avoid race condition on scheduler start
This commit is contained in:
@@ -132,8 +132,8 @@ impl Context {
|
||||
panic!("Already running");
|
||||
}
|
||||
|
||||
let scheduler = Scheduler::run(self.clone());
|
||||
*self.inner.scheduler.write().await = scheduler;
|
||||
let l = &mut *self.inner.scheduler.write().await;
|
||||
l.run(self.clone());
|
||||
}
|
||||
|
||||
pub async fn stop(&self) {
|
||||
|
||||
@@ -186,12 +186,20 @@ async fn smtp_loop(ctx: Context, smtp_handlers: SmtpConnectionHandlers) {
|
||||
|
||||
impl Scheduler {
|
||||
/// Start the scheduler, panics if it is already running.
|
||||
pub fn run(ctx: Context) -> Self {
|
||||
pub fn run(&mut self, ctx: Context) {
|
||||
let (mvbox, mvbox_handlers) = ImapConnectionState::new();
|
||||
let (sentbox, sentbox_handlers) = ImapConnectionState::new();
|
||||
let (smtp, smtp_handlers) = SmtpConnectionState::new();
|
||||
let (inbox, inbox_handlers) = ImapConnectionState::new();
|
||||
|
||||
*self = Scheduler::Running {
|
||||
inbox,
|
||||
mvbox,
|
||||
sentbox,
|
||||
smtp,
|
||||
probe_network: false,
|
||||
};
|
||||
|
||||
let ctx1 = ctx.clone();
|
||||
task::spawn(async move { inbox_loop(ctx1, inbox_handlers).await });
|
||||
|
||||
@@ -208,17 +216,8 @@ impl Scheduler {
|
||||
let ctx1 = ctx.clone();
|
||||
task::spawn(async move { smtp_loop(ctx1, smtp_handlers).await });
|
||||
|
||||
let res = Scheduler::Running {
|
||||
inbox,
|
||||
mvbox,
|
||||
sentbox,
|
||||
smtp,
|
||||
probe_network: false,
|
||||
};
|
||||
|
||||
info!(ctx, "scheduler is running");
|
||||
println!("RUN DONE");
|
||||
res
|
||||
}
|
||||
|
||||
fn set_probe_network(&mut self, val: bool) {
|
||||
|
||||
Reference in New Issue
Block a user