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

v0.1.x: allow overriding blocking behavior #1752

Merged
merged 8 commits into from Nov 12, 2019
Merged

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Nov 7, 2019

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, 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

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 hawkw self-assigned this Nov 7, 2019
// type to `Blocking::run_blocking`, we pass a _new_ closure which
// doesn't have a return value. That closure invokes the blocking
// function and assigns its value to `ret`, which we then unpack when
// the blocking call finishes.
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Ah, yes. This is the reason why the 0.2 version doesn't actually move the f anywhere, and instead executes it directly in the in_place function. I wonder if we could do something similar here.. But that may be too large a change to worry about it.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
as per @carllerche's suggestion

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw merged commit 9e91b8d into v0.1.x Nov 12, 2019
@taiki-e taiki-e deleted the eliza/blocking-compat-01 branch November 16, 2019 07:07
hawkw added a commit that referenced this pull request Dec 3, 2019
0.1.17 (December 3, 2019)

Added
- Internal APIs for overriding blocking behavior (#1752)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
carllerche pushed a commit that referenced this pull request Dec 4, 2019
0.1.17 (December 3, 2019)

Added
- Internal APIs for overriding blocking behavior (#1752)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
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.

None yet

2 participants