From 9396a09505026a4d01511651727ac541634ff437 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 11 Nov 2019 21:47:10 +0100 Subject: [PATCH] small fixes --- examples/repl/main.rs | 2 +- examples/simple.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/repl/main.rs b/examples/repl/main.rs index 76b2db853..f9e9773dc 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -211,7 +211,7 @@ fn start_threads(c: Arc>) -> Option>> { fn stop_threads(_context: &Context) { if let Some(ref mut handle) = *HANDLE.clone().lock().unwrap() { - !("Stopping threads"); + println!("Stopping threads"); IS_RUNNING.store(false, Ordering::Relaxed); handle.handle_imap.take().unwrap().join().unwrap(); diff --git a/examples/simple.rs b/examples/simple.rs index 440f9e129..1cae5eec6 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,6 +1,6 @@ extern crate deltachat; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, Mutex, RwLock}; use std::{thread, time}; use tempfile::tempdir; @@ -11,7 +11,8 @@ use deltachat::configure::*; use deltachat::contact::*; use deltachat::context::*; use deltachat::job::{ - perform_imap_fetch, perform_imap_idle, perform_imap_jobs, perform_smtp_idle, perform_smtp_jobs, + interrupt_imap_idle, perform_imap_fetch, perform_imap_idle, perform_imap_jobs, + perform_smtp_idle, perform_smtp_jobs, }; use deltachat::Event; @@ -45,19 +46,22 @@ fn main() { let duration = time::Duration::from_millis(4000); println!("info: {:#?}", info); + let inbox = Arc::new(Mutex::new(ctx.create_inbox())); + let inbox2 = inbox.clone(); let ctx = Arc::new(ctx); let ctx1 = ctx.clone(); + let r1 = running.clone(); let t1 = thread::spawn(move || { - let mut inbox = ctx1.create_inbox(); + let inbox = inbox2; while *r1.read().unwrap() { - perform_imap_jobs(&ctx1, &mut inbox); + perform_imap_jobs(&ctx1, &mut inbox.lock().unwrap()); if *r1.read().unwrap() { - perform_imap_fetch(&ctx1, &mut inbox); + perform_imap_fetch(&ctx1, &mut inbox.lock().unwrap()); if *r1.read().unwrap() { - perform_imap_idle(&ctx1, &mut inbox); + perform_imap_idle(&ctx1, &mut inbox.lock().unwrap()); } } } @@ -81,6 +85,8 @@ fn main() { ctx.set_config(config::Config::Addr, Some("d@testrun.org")) .unwrap(); ctx.set_config(config::Config::MailPw, Some(&pw)).unwrap(); + + interrupt_imap_idle(&ctx, &mut inbox.lock().unwrap()); configure(&ctx); thread::sleep(duration);