pub fn guarded<S: FnOnce() + Sync + Send + 'static>(
        initializer: impl FnOnce(),
        wake_up: impl FnOnce() -> S,
    ) -> Arc<ReaperGuard> {
        // This is supposed to be called in the main thread. A check is not necessary, because this
        // is protected by a mutex and it will fail in the initializer and getter if called from
        // wrong thread.
        let mut guard = REAPER_GUARD.lock().unwrap();
        if let Some(arc) = guard.upgrade() {
            // There's at least one active instance. No need to reactivate.
            return arc;
        }
        // There's no active instance.
        GUARD_INITIALIZER.call_once(|| {
            // If this is called, there was never an active instance in this session. Initialize!
            initializer();
        });
        let _ = Reaper::get().wake_up();
        let go_to_sleep = wake_up();
        let arc = Arc::new(ReaperGuard {
            go_to_sleep: Some(Box::new(go_to_sleep)),
        });
        *guard = Arc::downgrade(&arc);
        arc
    }
/// The given initializer is executed only the first time this is called.
///
/// `wake_up()` is called whenever first first instance pops up. `go_to_sleep()` is called
/// whenever the last instance goes away.
The given initializer is executed only the first time this is called.
`wake_up()` is called whenever first first instance pops up. `go_to_sleep()` is called
whenever the last instance goes away.
The given initializer is executed only the first time this is called . ` wake_up () ` is called whenever first first instance pops up . ` go_to_sleep () ` is called whenever the last instance goes away .
pub fn guarded<S: FnOnce() + Sync + Send + 'static>(
        initializer: impl FnOnce(),
        wake_up: impl FnOnce() -> S,
    ) -> Arc<ReaperGuard> {
        // This is supposed to be called in the main thread. A check is not necessary, because this
        // is protected by a mutex and it will fail in the initializer and getter if called from
        // wrong thread.
        let mut guard = REAPER_GUARD.lock().unwrap();
        if let Some(arc) = guard.upgrade() {
            // There's at least one active instance. No need to reactivate.
            return arc;
        }
        // There's no active instance.
        GUARD_INITIALIZER.call_once(|| {
            // If this is called, there was never an active instance in this session. Initialize!
            initializer();
        });
        let _ = Reaper::get().wake_up();
        let go_to_sleep = wake_up();
        let arc = Arc::new(ReaperGuard {
            go_to_sleep: Some(Box::new(go_to_sleep)),
        });
        *guard = Arc::downgrade(&arc);
        arc
    }
pub fn guarded < S : FnOnce ( ) + Sync + Send + ' static > ( initializer : impl FnOnce ( ) , wake_up : impl FnOnce ( ) -> S , ) -> Arc < ReaperGuard > { // This is supposed to be called in the main thread. A check is not necessary, because this // is protected by a mutex and it will fail in the initializer and getter if called from // wrong thread. let mut guard = REAPER_GUARD . lock ( ) . unwrap ( ) ; if let Some ( arc ) = guard . upgrade ( ) { // There's at least one active instance. No need to reactivate. return arc ; } // There's no active instance. GUARD_INITIALIZER . call_once ( | | { // If this is called, there was never an active instance in this session. Initialize! initializer ( ) ; } ) ; let _ = Reaper :: get ( ) . wake_up ( ) ; let go_to_sleep = wake_up ( ) ; let arc = Arc :: new ( ReaperGuard { go_to_sleep : Some ( Box :: new ( go_to_sleep ) ) , } ) ; * guard = Arc :: downgrade ( & arc ) ; arc }
The given initializer is executed only the first time this is called.
The given initializer is executed only the first time this is called .
initializer
impl FnOnce()
wake_up
impl FnOnce() -> S
initializer
impl FnOnce()
wake_up
impl FnOnce() -> S