You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-21 08:19:32 +02:00
Minor fix-ups to the async section. (#566)
These address some comments in #496.
This commit is contained in:
committed by
GitHub
parent
87f1976589
commit
d143528e07
@ -48,13 +48,14 @@ async fn main() {
|
||||
|
||||
<details>
|
||||
|
||||
* The difficulty with `async trait` is in that the resulting `Future` does not
|
||||
have a size known at compile time, because the size of the `Future` depends
|
||||
on the implementation.
|
||||
|
||||
* `async_trait` is easy to use, but note that it's using heap allocations to
|
||||
achieve this, and solve the unknow size problem above. This heap allocation
|
||||
has performance overhead.
|
||||
achieve this. This heap allocation has performance overhead.
|
||||
|
||||
* The challenges in language support for `async trait` are deep Rust and
|
||||
probably not worth describing in-depth. Niko Matsakis did a good job of
|
||||
explaining them in [this
|
||||
post](https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/)
|
||||
if you are interested in digging deeper.
|
||||
|
||||
* Try creating a new sleeper struct that will sleep for a random amount of time
|
||||
and adding it to the Vec.
|
||||
|
@ -103,8 +103,10 @@ async fn main() {
|
||||
iteration (a fused future would help with this). Update to reset
|
||||
`timeout_fut` every time it expires.
|
||||
|
||||
* Box allocates on the heap. In some cases, `tokio::pin!` is also an option, but
|
||||
* Box allocates on the heap. In some cases, `std::pin::pin!` (only recently
|
||||
stabilized, with older code often using `tokio::pin!`) is also an option, but
|
||||
that is difficult to use for a future that is reassigned.
|
||||
|
||||
* Another alternative is to not use `pin` at all but spawn another task that will send to a `oneshot` channel every 100ms.
|
||||
|
||||
</details>
|
||||
|
Reference in New Issue
Block a user