diff --git a/src/context.rs b/src/context.rs index 7c3e5879d..f5545c6ab 100644 --- a/src/context.rs +++ b/src/context.rs @@ -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) { diff --git a/src/scheduler.rs b/src/scheduler.rs index 458e29cb1..7f86d03e4 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -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) {