-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
compat: add a compat runtime #1663
Conversation
AFAICT the FreeBSD CI failures are spurious and appear to be occuring on master as well (https://github.com/tokio-rs/tokio/runs/260482009) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, nothing blocking on my end. I'd really like to ship this ASAP and get some sort of blog post up about how to use it. Thoughts @carllerche?
I'm definitely planning on doing a blog post! There are a couple things missing from the compat crate ( |
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Thanks @LucioFranco! Co-Authored-By: Lucio Franco <luciofranco14@gmail.com>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw those sound like a good plan to me |
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
I don't think it's possible for Unless there are any objections, I think we might want to do that in a subsequent PR. (cc @carllerche) |
@hawkw ah, I see. That would mean stuff like tokio-fs doesn't work... I have another thought... hear me out, and feel free to shoot it down. Have we considered updating tokio 0.1 to include a |
We can also add the necessary hooks to 0.1 to support blocking compat. |
Yeah, I think in order to get the ideal compat story for blocking, we'll need to make changes to the 0.1 runtime as well. I'm open to doing that, but I think it would be better to roll forward with these changes, if possible, and then move on to getting 0.1 blocking to work. |
👍 I'll leave the decisions to you & @LucioFranco. I'm just throwing out ideas. |
Things left are to fix I think @taiki-e is right we need to add Otherwise, I am happy with this change, the blocking stuff is somewhat not as important imo. Most users probably don't use that as much? For my use case I can easily swap out our blocking code. |
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
these pass, but it's good to have more tests Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Yup, looks like the
Fixed that one too, my bad!
I've added a note documenting that the compat runtime doesn't currently support legacy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets get this merged, I will contiue to look for issues in trying to convert my codebase over.
Originally from tokio-rs/tokio#1663
## Motivation The initial version of `tokio-compat`'s compatibility runtime added in #1663 doesn't support the calls to `tokio_threadpool` 0.1's `blocking`. This is because (unlike the timer, executor, and reactor), there's no way to override the global `blocking` functionality in `tokio-threadpool`. ## Solution As discussed [here][1], this branch adds APIs to the v0.1.x version of `tokio-threadpool` that allow overriding the behavior used by calls to `blocking`. The threadpool crate now exposes `blocking::set_default` and `blocking::with_default` functions, like `executor`, `timer`, and `reactor`. This will allow `tokio-compat` to override calls to 0.1's `blocking` to use the new `tokio` 0.2 blocking APIs. Unlike the similar APIs in `executor`, `timer`, and `reactor`, the hooks for overriding blocking behaviour are `#[doc(hidden)]` and have comments warning against their use outside of `tokio-compat`. In general, there probably won't be a compelling reason to override these outside of the compatibility layer. Refs: #1722 [1]: #1663 (comment) Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Motivation
The
futures
crate'scompat
module providesinteroperability between
futures
0.1 andstd::future
future types(e.g. implementing
std::future::Future
for a type that implements thefutures
0.1Future
trait). However, this on its own is insufficientto run code written against
tokio
0.1 on atokio
0.2 runtime, ifthat code also relies on
tokio
's runtime services. If legacy tasks areexecuted that rely on
tokio::timer
, perform IO usingtokio
'sreactor, or call
tokio::spawn
, those API calls will fail unless thereis also a runtime compatibility layer.
Solution
As proposed in #1549, this branch introduces a new
tokio-compat
crate,with implementations of the thread pool and current-thread runtimes that
are capable of running both tokio 0.1 and tokio 0.2 tasks. The compat
runtime creates a background thread that runs a
tokio
0.1 timer andreactor, and sets itself as the
tokio
0.1 executor as well as thedefault 0.2 executor. This allows 0.1 futures that use 0.1 timer,
reactor, and executor APIs may run alongside
std::future
tasks on the0.2 runtime.
Examples
Spawning both
tokio
0.1 andtokio
0.2 futures:Futures on the compat runtime can use
timer
APIs from both 0.1 and 0.2versions of
tokio
:Future Work
This is just an initial implementation of a
tokio-compat
crate; thereare more compatibility layers we'll want to provide before that crate is
complete. For example, we should also provide compatibility between
tokio
0.2'sAsyncRead
andAsyncWrite
traits and thefutures
0.1and
futures
0.3 versions of those traits. In #1549, @carllerche alsosuggests that the
compat
crate provide reimplementations of APIs thatwere removed from
tokio
0.2 proper, such as thetcp::Incoming
future.
Additionally, there is likely extra work required to get the
tokio-threadpool
0.1blocking
APIs to work on the compat runtime.This will be addressed in a follow-up PR.
Fixes: #1605
Fixes: #1552
Refs: #1549