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