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

How to shutdown the runtime when it is running the block_on method? #275

Open
lsk569937453 opened this issue Jul 23, 2024 · 1 comment
Open
Labels
F-feature-request feature request

Comments

@lsk569937453
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is that I want to shutdown the runtime when it is running on the block_on.

Describe the solution you'd like
Maybe we can pass the receiver of channle to the runtime when construct it.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context

std::thread::spawn(move || {
            let (stop_tx, stop_rx) = channel();
            let mut rt = monoio::RuntimeBuilder::<monoio::IoUringDriver>::new()
                .with_entries(256)
                .enable_timer()
                .build()
                .unwrap();
            rt.block_on(async { main_with_error().await });
        });

Maybe we can pass the stop_rx to the Runtimebuilder,and the runtime will shutdown when the stop_rx receive the message.

@lsk569937453 lsk569937453 added the F-feature-request feature request label Jul 23, 2024
@ihciah
Copy link
Member

ihciah commented Aug 26, 2024

Current task JoinHandle's output is not something like Result which means the main task can be interrupted, instead, it is returned only if the main task finishes normally.
This can be implemented as you mentioned, but to make it "zero-cost", I think users can do it manually. For example, create a channel and use select!{channel, original_main_task} as main task. In this way, there's no cost for users which hope it can be run forever, or, hope can exit on certain other things like signal instead of the channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-feature-request feature request
Projects
None yet
Development

No branches or pull requests

2 participants