refactor: get rid of ctx1 variables using rebinding

This commit is contained in:
Alexander Krotov
2021-01-12 21:28:49 +03:00
committed by link2xt
parent 5e8e77dfb6
commit 3c387a3cb3
2 changed files with 86 additions and 80 deletions

View File

@@ -592,13 +592,14 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
t.set_config(Config::ConfiguredAddr, Some("alice@example.com")) t.set_config(Config::ConfiguredAddr, Some("alice@example.com"))
.await .await
.unwrap(); .unwrap();
let thr0 = {
let ctx = t.clone(); let ctx = t.clone();
let ctx0 = ctx.clone(); thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx)))
let thr0 = };
thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx0))); let thr1 = {
let ctx1 = ctx; let ctx = t.clone();
let thr1 = thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx)))
thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx1))); };
let res0 = thr0.join().unwrap(); let res0 = thr0.join().unwrap();
let res1 = thr1.join().unwrap(); let res1 = thr1.join().unwrap();
assert_eq!(res0.unwrap(), res1.unwrap()); assert_eq!(res0.unwrap(), res1.unwrap());
@@ -617,10 +618,9 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
let t = TestContext::new().await; let t = TestContext::new().await;
let ctx = Arc::new(t); let ctx = Arc::new(t);
let ctx1 = ctx.clone();
let nrows = || async { let nrows = || async {
ctx1.sql ctx.sql
.query_get_value::<u32>(&ctx1, "SELECT COUNT(*) FROM keypairs;", paramsv![]) .query_get_value::<u32>(&ctx, "SELECT COUNT(*) FROM keypairs;", paramsv![])
.await .await
.unwrap() .unwrap()
}; };

View File

@@ -52,10 +52,10 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne
shutdown_sender, shutdown_sender,
} = inbox_handlers; } = inbox_handlers;
let ctx1 = ctx.clone(); let fut = {
let fut = async move { let ctx = ctx.clone();
async move {
started.send(()).await; started.send(()).await;
let ctx = ctx1;
// track number of continously executed jobs // track number of continously executed jobs
let mut jobs_loaded = 0; let mut jobs_loaded = 0;
@@ -94,6 +94,7 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne
} }
} }
} }
}
}; };
stop_receiver stop_receiver
@@ -179,15 +180,15 @@ async fn simple_imap_loop(
shutdown_sender, shutdown_sender,
} = inbox_handlers; } = inbox_handlers;
let ctx1 = ctx.clone(); let fut = {
let ctx = ctx.clone();
let fut = async move { async move {
started.send(()).await; started.send(()).await;
let ctx = ctx1;
loop { loop {
fetch_idle(&ctx, &mut connection, folder).await; fetch_idle(&ctx, &mut connection, folder).await;
} }
}
}; };
stop_receiver stop_receiver
@@ -211,10 +212,10 @@ async fn smtp_loop(ctx: Context, started: Sender<()>, smtp_handlers: SmtpConnect
idle_interrupt_receiver, idle_interrupt_receiver,
} = smtp_handlers; } = smtp_handlers;
let ctx1 = ctx.clone(); let fut = {
let fut = async move { let ctx = ctx.clone();
async move {
started.send(()).await; started.send(()).await;
let ctx = ctx1;
let mut interrupt_info = Default::default(); let mut interrupt_info = Default::default();
loop { loop {
@@ -232,6 +233,7 @@ async fn smtp_loop(ctx: Context, started: Sender<()>, smtp_handlers: SmtpConnect
} }
} }
} }
}
}; };
stop_receiver stop_receiver
@@ -259,16 +261,18 @@ impl Scheduler {
let mut sentbox_handle = None; let mut sentbox_handle = None;
let (smtp_start_send, smtp_start_recv) = channel(1); let (smtp_start_send, smtp_start_recv) = channel(1);
let ctx1 = ctx.clone(); let inbox_handle = {
let inbox_handle = Some(task::spawn(async move { let ctx = ctx.clone();
inbox_loop(ctx1, inbox_start_send, inbox_handlers).await Some(task::spawn(async move {
})); inbox_loop(ctx, inbox_start_send, inbox_handlers).await
}))
};
if ctx.get_config_bool(Config::MvboxWatch).await { if ctx.get_config_bool(Config::MvboxWatch).await {
let ctx1 = ctx.clone(); let ctx = ctx.clone();
mvbox_handle = Some(task::spawn(async move { mvbox_handle = Some(task::spawn(async move {
simple_imap_loop( simple_imap_loop(
ctx1, ctx,
mvbox_start_send, mvbox_start_send,
mvbox_handlers, mvbox_handlers,
Config::ConfiguredMvboxFolder, Config::ConfiguredMvboxFolder,
@@ -280,10 +284,10 @@ impl Scheduler {
} }
if ctx.get_config_bool(Config::SentboxWatch).await { if ctx.get_config_bool(Config::SentboxWatch).await {
let ctx1 = ctx.clone(); let ctx = ctx.clone();
sentbox_handle = Some(task::spawn(async move { sentbox_handle = Some(task::spawn(async move {
simple_imap_loop( simple_imap_loop(
ctx1, ctx,
sentbox_start_send, sentbox_start_send,
sentbox_handlers, sentbox_handlers,
Config::ConfiguredSentboxFolder, Config::ConfiguredSentboxFolder,
@@ -294,10 +298,12 @@ impl Scheduler {
sentbox_start_send.send(()).await; sentbox_start_send.send(()).await;
} }
let ctx1 = ctx.clone(); let smtp_handle = {
let smtp_handle = Some(task::spawn(async move { let ctx = ctx.clone();
smtp_loop(ctx1, smtp_start_send, smtp_handlers).await Some(task::spawn(async move {
})); smtp_loop(ctx, smtp_start_send, smtp_handlers).await
}))
};
*self = Scheduler::Running { *self = Scheduler::Running {
inbox, inbox,