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

main_exeuctor from smol-macros #134

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

brandonros
Copy link

@notgull
Copy link
Member

notgull commented Oct 27, 2024

I feel like this is an XY problem. What is the use case here? MainExecutor is an awkward interface for a public trait, which is why it's not public in smol-macros.

@brandonros
Copy link
Author

It lets me do this:

fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    Arc::<Executor>::with_main(|ex| smol::block_on(async_main(ex)))
}

while boils down to this:

impl MainExecutor for Arc<Executor<'_>> {
    #[inline]
    fn with_main<T, F: FnOnce(&Self) -> T>(f: F) -> T {
        let ex = Arc::new(Executor::new());
        with_thread_pool(&ex, || f(&ex))
    }
}

which is mildly less awkward / more clear (to me at least)

We can close it if you think it doesn't gain anything. It felt weird to me that async-executor ships without a default that can handle multiple tasks on different threads or whatever but only smol-macros did with it tucked away/private.

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

Successfully merging this pull request may close these issues.

2 participants