Skip to content

Reorganize the futures_core::task module #762

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

Merged
merged 1 commit into from
Feb 13, 2018
Merged

Reorganize the futures_core::task module #762

merged 1 commit into from
Feb 13, 2018

Conversation

alexcrichton
Copy link
Member

This commit is a large reorganization of the task module in accordance with
RFC 2 which added an explicit Context argument to all futures-related
functions. This argument is now explicitly constructed when necessary and
otherwise passed around in implementations of poll.

//! thought of as one unit, as the entire result is essentially just moving
//! through one large state machine.
//!
//! A "task" is the unit of abstraction for what is driving this state machine
Copy link
Member

@cramertj cramertj Feb 13, 2018

Choose a reason for hiding this comment

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

@aturon Is this still how we want to talk about "tasks"? My intuition always lead me to think that a "task" was the top-level future driven by an executor -- we'd even talked about trait Task = Future<Item = (), Error = ()>;.

Edit: from reading further, it's clear these aren't new docs-- github just thinks they are :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right yeah so I've just copied/pasted doc stuff around, I'm thinking we'll want docs to be a future PR. Right now it's all likely horribly outdated.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I will do a complete pass on the docs once the dust settles.

pub struct Context<'a> {
handle_factory: &'a (Fn() -> NotifyHandle + 'a),
id: usize,
map: &'a LocalMap,
Copy link
Member

@cramertj cramertj Feb 13, 2018

Choose a reason for hiding this comment

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

Why is this an immutable reference, rather than a mutable one? We are mutating the LocalMap, and it shouldn't be shared with anyone else at the time, should it?

Copy link
Member

Choose a reason for hiding this comment

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

Similarly, is there a reason the handle_factory is an &'a Fn() instead of an &'a mut FnMut?

Copy link
Member Author

Choose a reason for hiding this comment

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

An excellent point! Just a carryover from before, I'll change it to a mut everywhere.

/// This function will panic if a task is not currently being executed.
/// That is, this method can be dangerous to call outside of an
/// implementation of `poll`.
pub fn waker(&mut self) -> Task {
Copy link
Member

Choose a reason for hiding this comment

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

TODO: make this return a Waker rather than a Task.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure yeah, I can do that in this PR as well.

@alexcrichton alexcrichton force-pushed the rewrite-task branch 3 times, most recently from cc18ba0 to b7af114 Compare February 13, 2018 20:22
This commit is a large reorganization of the `task` module in accordance with
RFC 2 which added an explicit `Context` argument to all futures-related
functions. This argument is now explicitly constructed when necessary and
otherwise passed around in implementations of `poll`.
loop {
match future.poll_future_notify(&::IntoNotifyHandle(self.handle), 0) {
match future.poll(&mut task::Context::new(&mut map, 0, self.handle)) {
Copy link
Member

Choose a reason for hiding this comment

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

IMO this method is a bit confusing-- if i call task::Context::new(&mut map, 0, handle).block_on(fut) manually, it seems like i could reasonably expect it to use the LocalMap I provided, rather than generating a new one for this specific task. I guess this function will probably go away (or at least look different) in the new executor design, so maybe it's not worth worrying about now. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think let's revisit then.

@aturon
Copy link
Member

aturon commented Feb 13, 2018

Gonna go ahead and merge this and start hacking on the executor stuff and the Sink refactor.

@aturon aturon merged commit 03617f3 into 0.2 Feb 13, 2018
@alexcrichton alexcrichton deleted the rewrite-task branch February 13, 2018 23:16
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

Successfully merging this pull request may close these issues.

3 participants