1 // Take a look at the license at the top of the repository in the LICENSE file.
2 
3 use glib::*;
4 use std::sync::mpsc::{channel, Sender};
5 
6 #[allow(dead_code)]
run_async<T: Send + 'static, Q: FnOnce(Sender<T>, MainLoop) + Send + 'static>( start: Q, ) -> T7 pub fn run_async<T: Send + 'static, Q: FnOnce(Sender<T>, MainLoop) + Send + 'static>(
8     start: Q,
9 ) -> T {
10     let c = MainContext::new();
11     let l = MainLoop::new(Some(&c), false);
12     let l_clone = l.clone();
13 
14     let (tx, rx) = channel();
15 
16     c.push_thread_default();
17     c.invoke(move || {
18         start(tx, l_clone);
19     });
20 
21     l.run();
22     c.pop_thread_default();
23 
24     rx.recv().unwrap()
25 }
26 
27 #[allow(dead_code)]
run_async_local<T: 'static, Q: FnOnce(Sender<T>, MainLoop) + Send + 'static>(start: Q) -> T28 pub fn run_async_local<T: 'static, Q: FnOnce(Sender<T>, MainLoop) + Send + 'static>(start: Q) -> T {
29     let c = MainContext::new();
30     let l = MainLoop::new(Some(&c), false);
31     let l_clone = l.clone();
32 
33     let (tx, rx) = channel();
34 
35     c.push_thread_default();
36     c.invoke_local(move || {
37         start(tx, l_clone);
38     });
39 
40     l.run();
41     c.pop_thread_default();
42 
43     rx.recv().unwrap()
44 }
45