Use intermediate type for the callback promise

Using actual promises would still be better
This commit is contained in:
Alexandre Bury 2016-07-25 13:38:13 -07:00
parent c1c9322319
commit 5e6222bf23

View File

@ -7,15 +7,19 @@ use event::*;
use theme::ColorStyle;
use view::View;
pub type CbPromise = Option<Box<Fn(&mut Cursive) + Send>>;
/// Display progress.
pub struct ProgressBar {
min: usize,
max: usize,
value: Arc<AtomicUsize>,
// TODO: use a Promise instead?
callback: Option<Arc<Mutex<Option<Box<Fn(&mut Cursive) + Send>>>>>,
callback: Option<Arc<Mutex<CbPromise>>>,
}
new_default!(ProgressBar);
impl ProgressBar {
/// Creates a new progress bar.
///
@ -43,7 +47,7 @@ impl ProgressBar {
///
/// Whenever `callback` is set, it will be called on the next event loop.
pub fn with_callback(mut self,
callback: Arc<Mutex<Option<Box<Fn(&mut Cursive) + Send>>>>)
callback: Arc<Mutex<CbPromise>>)
-> Self {
self.callback = Some(callback);
self