forked from rust-lang/futures-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This bound existed for two primary reasons, both detail below, and both of which have now been solved. One of the primary reasons this existed was due to the presence of `tailcall`. Each standard combinator will call `tailcall` as appropriate, storing the resulting trait object. Storing trait objects influences the applicatoin of the `Send` and `Sync` bounds normally, but a key insight here is that we're not storing trait objects but rather just pieces of otherwise internal futures. With this insight the main storage for these futures, `Collapsed`, could simply implement `Send` so long as the future itself originally implemented `Send`. This in turn means that `tailcall` must be an `unsafe` method, but it seems well worth the benefit of relaxing the `Send` bound. The second primary reason for this bound was so the `Task` itself could be send. This is critical for ensuring that futures can receive notifications from multiple threads (e.g. be a future waiting on sources of multiple events). Another key insight here, however, is that only the *outer* future needs to be `Send`. We already have a solution, with `LoopData`, to make non-`Send` data `Send`. By implementing `Future` directly for `LoopData<F: Future>`, this means that it's trivial to make any future sendable by simply pinning it to an event loop! With these two pieces combined, it means that `Send` is no longer needed as a bound on the `Future` and `Stream` traits. It may practically mean that `LoopData` is used commonly in some scenarios, but that's quite a small price to pay for relaxing the requirements of the core trait. Some other ramifications of this change are: * The `Future::boxed` and `Stream::boxed` methods now require `Self` to adhere to `Send`. This is expected to be the most common case, and in the less common case of not-`Send` `Box::new` can be used. * Two new type aliases, `BoxFuture` and `BoxStream` have been introduced to assist in writing APIs that return a trait object which is `Send`. Both of these type aliases package in the `Send` bound. * A new `LoopPin` type, added in the previous commit, can be used to easily generate handles that can be used to pin futures to an event loop without having a literal reference to the event loop itself.
- Loading branch information
1 parent
250b115
commit 4d4ce22
Showing
55 changed files
with
420 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.