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

Add WeakShared. #2169

Merged
merged 1 commit into from
Oct 26, 2020
Merged

Add WeakShared. #2169

merged 1 commit into from
Oct 26, 2020

Conversation

khuey
Copy link
Contributor

@khuey khuey commented May 31, 2020

This makes implementing a cache with futures much easier. With the current architecture a cache that uses Shareds cannot honor the "drop as cancellation" feature of futures. And the cache is forced to either poll futures itself to ensure they're polled to completion or to leave half-polled futures dangling inside it (potentially consuming resources like sockets or database connections). WeakShared is to Shared as Weak is to Arc. If any copy of the underlying Shared exists that has not be dropped or polled to completion the WeakShared can be upgraded to it. This makes it possible to construct a cache that does not entrain futures, thus honoring the "drop as cancellation" feature.

@khuey
Copy link
Contributor Author

khuey commented Jul 26, 2020

Ping?

@khuey
Copy link
Contributor Author

khuey commented Oct 25, 2020

Looks like CI is finally happy.

Copy link
Member

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

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

Thanks for the PR and sorry for the delay reviewing. I have a few nits, but otherwise LGTM.

futures-util/src/future/future/shared.rs Outdated Show resolved Hide resolved
futures-util/src/future/future/shared.rs Outdated Show resolved Hide resolved
futures-util/src/future/future/shared.rs Outdated Show resolved Hide resolved
futures/tests/shared.rs Outdated Show resolved Hide resolved
This makes implementing a cache with futures much easier. With the current architecture a cache that uses Shareds cannot honor the "drop as cancellation" feature of futures. And the cache is forced to either poll futures itself to ensure they're polled to completion or to leave half-polled futures dangling inside it (potentially consuming resources like sockets or database connections). WeakShared is to Shared as Weak is to Arc. If any copy of the underlying Shared exists that has not be dropped or polled to completion the WeakShared can be upgraded to it. This makes it possible to construct a cache that does not entrain futures, thus honoring the "drop as cancellation" feature.
@taiki-e taiki-e merged commit 8bb7fd9 into rust-lang:master Oct 26, 2020
@khuey
Copy link
Contributor Author

khuey commented Oct 27, 2020

Thanks.

@khuey khuey deleted the weak_shared branch October 31, 2020 02:06
@taiki-e taiki-e mentioned this pull request Nov 4, 2020
@taiki-e taiki-e added the A-future Area: futures::future label Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-future Area: futures::future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants