Skip to content

debian-packaging: how to use the crate in multi_threaded tokio runtime? #25

Open
@sify21

Description

@sify21

Qutting https://stackoverflow.com/questions/75079221/future-created-by-async-block-is-not-send

The tokio Runtime is usually multi-threaded, meaning that at any .await point your task could get moved from one thread to another. That's why everything that is held across an .await point must be Send.

I also intend to use in async_trait methods, which by default require Send.

However, many structs in debian-packaging are not Send. For example, I want to unpack data_tar_reader inside BinaryPackageEntry, which causes errors like this:

error: future cannot be sent between threads safely
..... some code here
    | |_____^ future created by async block is not `Send`
    |
    = help: the trait `std::marker::Send` is not implemented for `(dyn futures::AsyncRead + Unpin + 'static)`
note: future is not `Send` as this value is used across an await
241 |     while let Some(Ok(e)) = a.next_entry() {
    |                       - has type `BinaryPackageEntry` which is not `Send`
...
282 |                 data_tar_reader.into_inner().unpack(&dst).await?;
    |                                                           ^^^^^ await occurs here, with `e` maybe used later

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions