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
Describe the bug Functions that return
Paginator<T>
do not implementSend
, preventing it from being used in stuff liketokio::spawn()
Sample code
Attached Compiler Error