Skip to content

Conversation

@alexcrichton
Copy link
Member

This commit adds a new trait, Wait, to serve as the implementation for
functions like Future::wait. The intention for this trait is for executors to
be able to customize the blocking behavior of futures.

Closes #360

@carllerche
Copy link
Contributor

As a reference, here is the tokio-core snippet from #436 (comment).

extern crate tokio_core;

fn main() {
    tokio_core::run(|handle| {
        let future = ...;
        let result = future.wait();
        println!("{:?}", result);
    });
}

Copy link
Contributor

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

Seems good. I added a comment regarding the panic guarantees of Wait::wait.

/// called recursively due to multiple invocations of `Future::wait` on the
/// stack. In other words its expected for executors to handle
/// waits-in-waits correctly.
fn wait(&self);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that this function should be permitted to panic if the current executor does not allow for blocking the current thread.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah right yes good point.

/// It is expected that this method will not panic. This method may be
/// called recursively due to multiple invocations of `Future::wait` on the
/// stack. In other words its expected for executors to handle
/// waits-in-waits correctly.
Copy link

@tanriol tanriol May 30, 2017

Choose a reason for hiding this comment

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

Does this imply that in case of recursion the inner wait invocation may block the outer one until the inner wait finishes? This does not sound like "shortly thereafter".

Copy link
Contributor

Choose a reason for hiding this comment

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

@tanriol you are very correct. If nested calls to wait are done, then there are no guarantees as to when wait returns. In fact, there could be cases where wait never returns (because someone called wait on tcp_listener.incoming().for_each(...).

This is definitely a significant hazard and great care should be taken with this feature.

@alexcrichton
Copy link
Member Author

Ok, I've pushed an updated which I believe addresses comments. I'd like to integrate this into tokio-core first before landing.

@carllerche
Copy link
Contributor

I think it would be wise to first agree how tokio-core should use this. I have significant reservations about supporting recursive calls to wait w/ tokio-core as there is no way to guarantee that futures ever complete. This isn't just a hypothetical concern as historically, other "future" platforms built on top of Java's Fork/Join pool did exactly this and my recollection is that it did not end well.

IIRC, this was attempted w/ Akka and other less known libs and has since been removed. Maybe someone who is more familiar w/ these libs could provide further insight.

This commit adds a new trait, `Wait`, to serve as the implementation for
functions like `Future::wait`. The intention for this trait is for executors to
be able to customize the blocking behavior of futures.

Closes #360
@carllerche
Copy link
Contributor

I believe this this is now a "won't fix" with the direction being taken in #645. Please re-open if I am wrong.

@carllerche carllerche closed this Dec 15, 2017
@taiki-e taiki-e deleted the local-wait branch March 30, 2023 16:46
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.

4 participants