Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a composed primitive Shutdown #35

Open
tisonkun opened this issue Feb 12, 2025 · 0 comments
Open

Implement a composed primitive Shutdown #35

tisonkun opened this issue Feb 12, 2025 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@tisonkun
Copy link
Collaborator

#[derive(Debug, Clone)]
pub struct Shutdown {
    latch: Arc<Latch>,
    wg: WaitGroup,
}

impl Shutdown {
    pub fn new() -> Self {
        Shutdown {
            latch: Arc::new(Latch::new(1)),
            wg: WaitGroup::new(),
        }
    }

    pub fn shutdown(&self) {
        self.latch.count_down();
    }

    pub async fn await_shutdown(self) {
        self.wg.await;
    }
}

This is used in ScopeDB to synchronize the shutdown of scheduled actions.

@tisonkun tisonkun added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant