/// Initializes `Updater` to fetch latest release information.
///
/// - If it has been more than [`UPDATE_INTERVAL`] seconds (see [`set_interval()`]) since last check,
/// the method will spawn a worker thread.
/// In the background, the spawned thread will attempt to make a network call to fetch metadata of releases
/// *only if* `UPDATE_INTERVAL` seconds has passed since the last network call.
///
/// - All calls, which happen before the `UPDATE_INTERVAL` seconds, will initialize the `Updater`
/// by using a local cache to report metadata about a release.
///
/// For `Updater`s talking to `github.com`, the worker thread will only fetch a small
/// metadata information to extract the version of the latest release.
///
/// To check on status of worker thread and to get latest release status, use either of
/// [`update_ready()`] or [`try_update_ready()`] methods.
///
/// # Example
///
/// ```rust,no_run
/// # extern crate alfred_rs;
/// # extern crate failure;
/// # use failure::Error;
/// # use alfred_rs::Updater;
/// # use std::env;
/// # fn do_some_other_stuff() {}
/// # fn test_async() -> Result<(), Error> {
/// let updater = Updater::gh("spamwax/alfred-pinboard-rs")?;
///
/// let rx = updater.init().expect("Error in starting updater.");
///
/// // We'll do some other work that's related to our workflow while waiting
/// do_some_other_stuff();
///
/// // We can now check if update is ready using two methods:
/// // 1- Block and wait until we receive results or errors
/// let update_status = updater.update_ready();
///
/// // 2- Or without blocking, check if the worker thread sent the results.
/// //    If the worker thread is still busy, we'll get an `Err`
/// let update_status = updater.try_update_ready();
///
/// if let Ok(is_ready) = update_status {
///     // Everything went ok:
///     // No error happened during operation of worker thread
///     // and we received release info
///     if is_ready {
///         // there is an update available.
///     }
/// } else {
///     /* either the worker thread wasn't successful or we couldn't get its results */
/// }
/// # Ok(())
/// # }
/// # fn main() {
/// # test_async();
/// # }
/// ```
///
/// # Errors
/// Followings can cause the method return an error:
/// - A worker thread cannot be spawned
/// - Alfred environment variable error
/// - File IO error
///
/// [`set_interval()`]: struct.Updater.html#method.set_interval
/// [`update_ready()`]: struct.Updater.html#method.update_ready
/// [`try_update_ready()`]: struct.Updater.html#method.try_update_ready
/// [`UPDATE_INTERVAL`]: constant.UPDATE_INTERVAL.html
Initializes `Updater` to fetch latest release information.
If it has been more than [`UPDATE_INTERVAL`] seconds `]) since last check,
the method will spawn a worker thread.
In the background, the spawned thread will attempt to make a network call to fetch metadata of releases
only if* `UPDATE_INTERVAL` seconds has passed since the last network call.

All calls, which happen before the `UPDATE_INTERVAL` seconds, will initialize the `Updater`
by using a local cache to report metadata about a release.

For `Updater`s talking to `github.com`, the worker thread will only fetch a small
metadata information to extract the version of the latest release.

To check on status of worker thread and to get latest release status, use either of
[`update_ready()`] or [`try_update_ready()`] methods.
Initializes ` Updater ` to fetch latest release information . If it has been more than [ ` UPDATE_INTERVAL ` ] seconds ` ] ) since last check the method will spawn a worker thread . In the background the spawned thread will attempt to make a network call to fetch metadata of releases only if * ` UPDATE_INTERVAL ` seconds has passed since the last network call . All calls which happen before the ` UPDATE_INTERVAL ` seconds will initialize the ` Updater ` by using a local cache to report metadata about a release . For ` Updater ` s talking to ` github . com ` the worker thread will only fetch a small metadata information to extract the version of the latest release . To check on status of worker thread and to get latest release status use either of [ ` update_ready () ` ] or [ ` try_update_ready () ` ] methods .
pub fn init(&self) -> Result<(), Error> {
        let _ = env_logger::try_init();
        debug!("entering init");
        use self::imp::LATEST_UPDATE_INFO_CACHE_FN_ASYNC;
        use std::sync::mpsc;
        // file for status of last update check
        let p = Self::build_data_fn()?.with_file_name(LATEST_UPDATE_INFO_CACHE_FN_ASYNC);
        let (tx, rx) = mpsc::channel();
        if self.last_check().is_none() {
            self.set_last_check(Utc::now());
            self.save()?;
            // This send is always successful
            tx.send(Ok(None)).unwrap();
            debug!("  last check was set to now()");
        } else if self.due_to_check() {
            // it's time to talk to remote server
            debug!(" calling start_releaser_worker");
            self.start_releaser_worker(tx, p)?;
        } else {
            debug!("  calling read_last_check_status");
            let status = Self::read_last_check_status(&p)
                .map(|last_check| {
                    last_check.and_then(|info| {
                        debug!("  read last_check_status: {:?}", info);
                        if self.current_version() < info.version() {
                            Some(info)
                        } else {
                            None
                        }
                    })
                })
                .or(Ok(None));
            debug!("  status: {:?}", status);
            tx.send(status).unwrap();
        }
        *self.state.borrow_worker_mut() = Some(imp::MPSCState::new(rx));
        debug!("successfully set the state of release worker");
        Ok(())
    }
pub fn init ( & self ) -> Result < ( ) , Error > { let _ = env_logger :: try_init ( ) ; debug ! ( " " ) ; use self :: imp :: LATEST_UPDATE_INFO_CACHE_FN_ASYNC ; use std :: sync :: mpsc ; // file for status of last update check let p = Self :: build_data_fn ( ) ? . with_file_name ( LATEST_UPDATE_INFO_CACHE_FN_ASYNC ) ; let ( tx , rx ) = mpsc :: channel ( ) ; if self . last_check ( ) . is_none ( ) { self . set_last_check ( Utc :: now ( ) ) ; self . save ( ) ? ; // This send is always successful tx . send ( Ok ( None ) ) . unwrap ( ) ; debug ! ( " " ) ; } else if self . due_to_check ( ) { // it's time to talk to remote server debug ! ( " " ) ; self . start_releaser_worker ( tx , p ) ? ; } else { debug ! ( " " ) ; let status = Self :: read_last_check_status ( & p ) . map ( | last_check | { last_check . and_then ( | info | { debug ! ( " " info ) ; if self . current_version ( ) < info . version ( ) { Some ( info ) } else { None } } ) } ) . or ( Ok ( None ) ) ; debug ! ( " " status ) ; tx . send ( status ) . unwrap ( ) ; } * self . state . borrow_worker_mut ( ) = Some ( imp :: MPSCState :: new ( rx ) ) ; debug ! ( " " ) ; Ok ( ( ) ) }
Initializes `Updater` to fetch latest release information.
Initializes ` Updater ` to fetch latest release information .
&self
example
None
extern crate alfred_rs;
None
extern crate failure;
None
use failure::error;
None
use alfred_rs::updater;
None
use std::env;
None
fn do_some_other_stuff() {}
None
fn test_async() -> result<(), error> {
let updater = Updater::gh("spamwax/alfred-pinboard-rs")?.

let rx = updater.init().expect("Error in starting updater.").

We'll do some other work that's related to our workflow while waiting
do_some_other_stuff().

We can now check if update is ready using two methods:
1- Block and wait until we receive results or errors
let update_status = updater.update_ready().

2- Or without blocking, check if the worker thread sent the results.
If the worker thread is still busy, we'll get an `Err`
let update_status = updater.try_update_ready().

if let Ok(is_ready) = update_status {
Everything went ok:
No error happened during operation of worker thread
and we received release info
if is_ready {
there is an update available.
}
} else {
either the worker thread wasn't successful or we couldn't get its results
}
let updater = Updater :: gh ( " spamwax / alfred - pinboard - rs " ) ? . let rx = updater . init () . expect ( " Error in starting updater . " ) . We ' ll do some other work that ' s related to our workflow while waiting do_some_other_stuff () . We can now check if update is ready using two methods : 1 - Block and wait until we receive results or errors let update_status = updater . update_ready () . 2 - Or without blocking check if the worker thread sent the results . If the worker thread is still busy we ' ll get an ` Err ` let update_status = updater . try_update_ready () . if let Ok ( is_ready ) = update_status { Everything went ok : No error happened during operation of worker thread and we received release info if is_ready { there is an update available . } } else { either the worker thread wasn ' t successful or we couldn ' t get its results }
ok(())
None
}
None
fn main() {
None
test_async();
None
}
None
errors
Followings can cause the method return an error:
A worker thread cannot be spawned
Alfred environment variable error
File IO error

[`set_interval()`]: struct.Updater.html#method.set_interval
[`update_ready()`]: struct.Updater.html#method.update_ready
[`try_update_ready()`]: struct.Updater.html#method.try_update_ready
[`UPDATE_INTERVAL`]: constant.UPDATE_INTERVAL.html
Followings can cause the method return an error : A worker thread cannot be spawned Alfred environment variable error File IO error [ ` set_interval () ` ] : struct . Updater . html#method . set_interval [ ` update_ready () ` ] : struct . Updater . html#method . update_ready [ ` try_update_ready () ` ] : struct . Updater . html#method . try_update_ready [ ` UPDATE_INTERVAL ` ] : constant . UPDATE_INTERVAL . html