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

[Refactor] Refactor the shutdown channel #174

Closed
Phoenix500526 opened this issue Feb 9, 2023 · 0 comments
Closed

[Refactor] Refactor the shutdown channel #174

Phoenix500526 opened this issue Feb 9, 2023 · 0 comments
Assignees

Comments

@Phoenix500526
Copy link
Collaborator

Currently, our curp server will abort all the background tasks via a Shutdown instance. When a Protocol instance is dropped, it will send a message to notify a background task to abort other tasks. Some relevant codes are shown below:

/// Shutdown broadcast wrapper
#[derive(Debug)]
pub(crate) struct Shutdown {
    /// `true` if the shutdown signal has been received
    shutdown: bool,
    /// The receive half of the channel used to listen for shutdown.
    notify: broadcast::Receiver<()>,
}

impl<C: 'static + Command> Drop for Protocol<C> {
     #[inline]
     fn drop(&mut self) {
         // TODO: async drop is still not supported by Rust(should wait for bg tasks to be stopped?), or we should create an async `stop` function for Protocol
        let _ = self.stop_tx.send(()).ok();
     }
 }

However, we don't need to record this shutdown bool variable, since this shutdown channel will only be notified once. Thus, we can use an event listener to replace the Shutdown struct.

@Phoenix500526 Phoenix500526 self-assigned this Feb 9, 2023
Phoenix500526 added a commit to Phoenix500526/Xline that referenced this issue Feb 9, 2023
Phoenix500526 added a commit to Phoenix500526/Xline that referenced this issue Feb 9, 2023
Phoenix500526 added a commit to Phoenix500526/Xline that referenced this issue Feb 9, 2023
Phoenix500526 added a commit to Phoenix500526/Xline that referenced this issue Feb 9, 2023
Phoenix500526 added a commit to Phoenix500526/Xline that referenced this issue Feb 10, 2023
Phoenix500526 added a commit to Phoenix500526/Xline that referenced this issue Feb 10, 2023
Phoenix500526 added a commit to Phoenix500526/Xline that referenced this issue Feb 10, 2023
Phoenix500526 added a commit to Phoenix500526/Xline that referenced this issue Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant