[GH-ISSUE #334] Async Paginator<T> does not seem to be Send #105

Closed
opened 2026-02-27 20:23:08 +03:00 by kerem · 1 comment
Owner

Originally created by @powpingdone on GitHub (Jun 23, 2022).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/334

Describe the bug
Functions that return Paginator<T> do not implement Send, preventing it from being used in stuff like tokio::spawn()

Sample code

    'big: while let Some(plist) = rx.recv().await {

        // gather tracks
        wait!(w);
        let mut plist_items = ~139
            client.playlist_items(&plist, Some("items.track.(id,preview_url)"), None); // creates a stream
        // other things...
        wait!(w);
        while let Some(Ok(track)) = plist_items.next().await {
            // doing stuff with `track`
            wait!(w);
        }

        // send tracks
        tx_track.send((plist.clone(), tracks_url)).await.unwrap();
        tx_meta.send((plist.clone(), tracks)).await.unwrap(); ~160
    } ~163

Attached Compiler Error

error: future cannot be sent between threads safely
   --> src/main.rs:286:22
    |
286 |         tokio::spawn(playlist_track_scrape(gov.clone(), pb1, rx_ps, tx_track, tx_meta)),
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `playlist_track_scrape` is not `Send`
    |
    = help: the trait `std::marker::Send` is not implemented for `dyn futures::Stream<Item = Result<PlaylistItem, ClientError>>`
note: future is not `Send` as this value is used across an await
   --> src/main.rs:160:46
    |
139 |         let mut plist_items =
    |             --------------- has type `Pin<Box<dyn futures::Stream<Item = Result<PlaylistItem, ClientError>>>>` which is not `Send`
...
160 |         tx_meta.send((plist.clone(), tracks)).await.unwrap();
    |                                              ^^^^^^ await occurs here, with `mut plist_items` maybe used later
163 |     }
    |     - `mut plist_items` is later dropped here
Originally created by @powpingdone on GitHub (Jun 23, 2022). Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/334 **Describe the bug** Functions that return `Paginator<T>` do not implement `Send`, preventing it from being used in stuff like `tokio::spawn()` **Sample code** ```rust 'big: while let Some(plist) = rx.recv().await { // gather tracks wait!(w); let mut plist_items = ~139 client.playlist_items(&plist, Some("items.track.(id,preview_url)"), None); // creates a stream // other things... wait!(w); while let Some(Ok(track)) = plist_items.next().await { // doing stuff with `track` wait!(w); } // send tracks tx_track.send((plist.clone(), tracks_url)).await.unwrap(); tx_meta.send((plist.clone(), tracks)).await.unwrap(); ~160 } ~163 ``` **Attached Compiler Error** ```rust error: future cannot be sent between threads safely --> src/main.rs:286:22 | 286 | tokio::spawn(playlist_track_scrape(gov.clone(), pb1, rx_ps, tx_track, tx_meta)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `playlist_track_scrape` is not `Send` | = help: the trait `std::marker::Send` is not implemented for `dyn futures::Stream<Item = Result<PlaylistItem, ClientError>>` note: future is not `Send` as this value is used across an await --> src/main.rs:160:46 | 139 | let mut plist_items = | --------------- has type `Pin<Box<dyn futures::Stream<Item = Result<PlaylistItem, ClientError>>>>` which is not `Send` ... 160 | tx_meta.send((plist.clone(), tracks)).await.unwrap(); | ^^^^^^ await occurs here, with `mut plist_items` maybe used later 163 | } | - `mut plist_items` is later dropped here ```
kerem 2026-02-27 20:23:08 +03:00
Author
Owner

@powpingdone commented on GitHub (Jul 2, 2022):

Lack of knowledge on my part caused this. Sorry.

<!-- gh-comment-id:1172929798 --> @powpingdone commented on GitHub (Jul 2, 2022): Lack of knowledge on my part caused this. Sorry.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#105
No description provided.