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

Specify that runtime should have task scheduler #1839

Merged

Conversation

olegnn
Copy link
Contributor

@olegnn olegnn commented Nov 27, 2019

Motivation

If runtime doesn't have task scheduler,tokio::spawn from context of this runtime will produce panic must be called from the context of Tokio runtime, which is unclear, because it's actually done from the context of runtime. New panic message specifies that runtime should have task scheduler in order to execute spawned tasks.

Solution

Changed runtime panic message. Closes #1837.

@@ -47,7 +47,7 @@ where
// Explicit drop of `future` silences the warning that `future` is
// not used when neither rt-* feature flags are enabled.
drop(future);
panic!("must be called from the context of Tokio runtime");
panic!("must be called from the context of Tokio runtime with task scheduler");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

Suggested change
panic!("must be called from the context of Tokio runtime with task scheduler");
panic!("must be called from the context of Tokio runtime configured with either `basic_scheduler` or `threaded_scheduler`");

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that committing ^^ as is will make rustfmt unhappy though.

@carllerche
Copy link
Member

Thanks for the panic message PR 👍 I greatly appreciate these kinds of contributions. Fixing pain points is great.

@olegnn
Copy link
Contributor Author

olegnn commented Nov 27, 2019

Also there's still a thing that can confuse people - calling num_threads() on Builder without call of threaded_scheduler in fact does nothing.
Maybe it's a good idea to make debug assertion for this case or warning at least?
Because when I write code like

let rt = tokio::runtime::Builder::new().num_threads(4).build().unwrap();

I don't expect that num_threads is useless unless threaded_scheduler method is called.

@carllerche
Copy link
Member

Thanks 👍

@carllerche carllerche merged commit 2cd1d74 into tokio-rs:master Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants