tokio-rs / doc-push

Tokio doc blitz effort - A concerted effort to improve Tokio's documentation.
MIT License
50 stars 7 forks source link

doc: TaskExecutor #66

Open bbigras opened 6 years ago

bbigras commented 6 years ago

The user of TaskExecutor must ensure that when a future is submitted, that it is done within the context of a call to run.

For more details, see the module level documentation.

https://docs.rs/tokio/0.1.11/tokio/runtime/current_thread/struct.TaskExecutor.html#method.current

I'm confused by the "within the context of a call to run" part. Does it just mean that I must only call current() from code being executed by tokio?

carllerche commented 6 years ago

You are correct, that is very poorly worded.

Basically, you need to use TaskExecutor from a future spawned on tokio::run. TaskExecutor uses a thread-local variable referencing the "current executor". Until you are running on the tokio runtime (with tokio::run) that thread-local is not set.

Does that make sense?

bbigras commented 6 years ago

Yes it does, thanks!

carllerche commented 6 years ago

Great. This issue can be closed once the API docs have been updated.

shaitao commented 5 years ago

Great. This issue can be closed once the API docs have been updated.

It would be good to have some theroy guide or reference regardless of code and language.