[GH-ISSUE #79] The workload of adding support for async/await. #23

Closed
opened 2026-02-27 20:22:39 +03:00 by kerem · 0 comments
Owner

Originally created by @ramsayleung on GitHub (Feb 24, 2020).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/79

I have refactored the core code of Rspotify to support async/await, and refactored the project structure to shorten import path either. Now the foundation is done, it's time to build the roof, and it'll be great if you have time to help me do this:
The following endpoint functions need to be asynced/awaited before Rspotify can take advantage of async/await, check this branch: ramsay/support-for-async-await for more details:

  • artist
  • artists
  • artist_albums
  • artists
  • artist_albums
  • artist_top_tracks
  • artist_related_artists
  • album
  • albums
  • search_album
  • search_artist
  • search_track
  • search_playlist
  • album_track
  • user
  • playlist
  • current_user_playlists
  • user_playlists
  • user_playlist
  • user_playlist_tracks
  • user_playlist_create
  • user_playlist_change_detail
  • user_playlist_unfollow
  • user_playlist_add_tracks
  • user_playlist_replace_tracks
  • user_playlist_recorder_tracks
  • user_playlist_remove_all_occurrences_of_tracks
  • user_playlist_remove_specific_occurrenes_of_tracks
  • user_playlist_follow_playlist
  • user_playlist_check_follow
  • me
  • current_user
  • current_user_playing_track
  • current_user_saved_albums
  • current_user_saved_tracks
  • current_user_followed_artists
  • current_user_saved_tracks_delete
  • current_user_saved_tracks_contains
  • current_user_saved_tracks_add
  • current_user_top_artists
  • current_user_top_tracks
  • current_user_recently_played
  • current_user_saved_albums_add
  • current_user_saved_albums_delete
  • current_user_saved_albums_contains
  • user_follow_artists
  • user_unfollow_artists
  • user_artist_check_follow
  • user_follow_users
  • user_unfollow_users
  • featured_playlists
  • new_releases
  • categories
  • recommendations
  • audio_features
  • audios_features
  • audio_analysis
  • device
  • current_playback
  • current_playing
  • transfer_playback
  • start_playback
  • pause_playback
  • next_track
  • previous_track
  • seek_track
  • repeat
  • volume
  • shuffle

the following examples need to update to async/await version, for example:

extern crate rspotify;

use futures;
use rspotify::client::Spotify;
use rspotify::oauth2::SpotifyClientCredentials;
use tokio;

#[tokio::main]
async fn main() {
    let mut handlers = vec![];
    for _ in 0..20 {
        let handler = tokio::spawn(async move {
            // Set client_id and client_secret in .env file or
            // export CLIENT_ID="your client_id"
            // export CLIENT_SECRET="secret"
            let client_credential = SpotifyClientCredentials::default().build();

            // Or set client_id and client_secret explictly
            // let client_credential = SpotifyClientCredentials::default()
            //     .client_id("this-is-my-client-id")
            //     .client_secret("this-is-my-client-secret")
            //     .build();
            let spotify = Spotify::default()
                .client_credentials_manager(client_credential)
                .build();
            let birdy_uri = "spotify:artist:2WX2uTcsvV5OnS0inACecP";
            let artist = spotify.artist(birdy_uri).await;
            println!("{:?}", artist);
            return;
        });
        handlers.push(handler);
    }
    futures::future::join_all(handlers).await;
}
  • artists
  • track
  • artists_albums
  • artist_related_artists
  • albums
  • audios_features
  • audio_analysis
  • album_tracks
  • audio_features
  • artist
  • album

the following example need to move to blocking directory, and explicitly set required-feature=["blocking"], for example:

[[example]]
name = "device"
required-features = ["blocking"]
path = "examples/blocking/device.rs"
  • device
  • artist_top_tracks
  • categories
  • current_playback
  • current_playing
  • current_user_followed_artists
  • current_user_playing_track
  • current_user_playlists
  • current_user_recently_played
  • current_user_saved_albums_add
  • current_user_saved_albums_contains
  • current_user_saved_albums_delete
  • current_user_saved_albums
  • current_user_saved_tracks_add
  • current_user_saved_tracks_contains
  • current_user_saved_tracks_delete
  • current_user_saved_tracks
  • current_user_top_artists
  • current_user_top_tracks
  • featured_playlists
  • me
  • new_releases
  • next_playback
  • pause_playback
  • playlist
  • previous_playback
  • recommendations
  • repeat
  • search_album
  • search_artist
  • search_playlist
  • search_track
  • seek_track
  • shuffle
  • start_playback
  • transfer_playback
  • user_artist_check_follow
  • user_follow_artists
  • user_follow_users
  • user_playlist_add_tracks
  • user_playlist_change_detail
  • user_playlist_check_follow
  • user_playlist_create
  • user_playlist_follow_playlist
  • user_playlist_recorder_tracks
  • user_playlist_remove_all_occurrences_of_tracks
  • user_playlist_remove_specific_occurrenes_of_tracks
  • user_playlist_replace_tracks
  • user_playlist
  • user_playlists
  • user_playlist_tracks
  • user_playlist_unfollow
  • user_unfollow_artists
  • user_unfollow_users
  • volume
Originally created by @ramsayleung on GitHub (Feb 24, 2020). Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/79 I have refactored the core code of `Rspotify` to support `async/await`, and refactored the project structure to shorten import path either. Now the foundation is done, it's time to build the roof, and it'll be great if you have time to help me do this: The following endpoint functions need to be `asynced/awaited` before Rspotify can take advantage of `async/await`, check this [branch: ramsay/support-for-async-await](https://github.com/ramsayleung/rspotify/tree/ramsay/support-for-async-await) for more details: - [x] artist - [x] artists - [x] artist_albums - [x] artists - [x] artist_albums - [x] artist_top_tracks - [x] artist_related_artists - [x] album - [x] albums - [x] search_album - [x] search_artist - [x] search_track - [x] search_playlist - [x] album_track - [x] user - [x] playlist - [x] current_user_playlists - [x] user_playlists - [x] user_playlist - [x] user_playlist_tracks - [x] user_playlist_create - [x] user_playlist_change_detail - [x] user_playlist_unfollow - [x] user_playlist_add_tracks - [x] user_playlist_replace_tracks - [x] user_playlist_recorder_tracks - [x] user_playlist_remove_all_occurrences_of_tracks - [x] user_playlist_remove_specific_occurrenes_of_tracks - [x] user_playlist_follow_playlist - [x] user_playlist_check_follow - [x] me - [x] current_user - [x] current_user_playing_track - [x] current_user_saved_albums - [x] current_user_saved_tracks - [x] current_user_followed_artists - [x] current_user_saved_tracks_delete - [x] current_user_saved_tracks_contains - [x] current_user_saved_tracks_add - [x] current_user_top_artists - [x] current_user_top_tracks - [x] current_user_recently_played - [x] current_user_saved_albums_add - [x] current_user_saved_albums_delete - [x] current_user_saved_albums_contains - [x] user_follow_artists - [x] user_unfollow_artists - [x] user_artist_check_follow - [x] user_follow_users - [x] user_unfollow_users - [x] featured_playlists - [x] new_releases - [x] categories - [x] recommendations - [x] audio_features - [x] audios_features - [x] audio_analysis - [x] device - [x] current_playback - [x] current_playing - [x] transfer_playback - [x] start_playback - [x] pause_playback - [x] next_track - [x] previous_track - [x] seek_track - [x] repeat - [x] volume - [x] shuffle the following examples need to update to `async/await` version, for example: ```rust extern crate rspotify; use futures; use rspotify::client::Spotify; use rspotify::oauth2::SpotifyClientCredentials; use tokio; #[tokio::main] async fn main() { let mut handlers = vec![]; for _ in 0..20 { let handler = tokio::spawn(async move { // Set client_id and client_secret in .env file or // export CLIENT_ID="your client_id" // export CLIENT_SECRET="secret" let client_credential = SpotifyClientCredentials::default().build(); // Or set client_id and client_secret explictly // let client_credential = SpotifyClientCredentials::default() // .client_id("this-is-my-client-id") // .client_secret("this-is-my-client-secret") // .build(); let spotify = Spotify::default() .client_credentials_manager(client_credential) .build(); let birdy_uri = "spotify:artist:2WX2uTcsvV5OnS0inACecP"; let artist = spotify.artist(birdy_uri).await; println!("{:?}", artist); return; }); handlers.push(handler); } futures::future::join_all(handlers).await; } ``` - [x] artists - [x] track - [x] artists_albums - [x] artist_related_artists - [x] albums - [x] audios_features - [x] audio_analysis - [x] album_tracks - [x] audio_features - [x] artist - [x] album the following example need to move to `blocking` directory, and explicitly set `required-feature=["blocking"]`, for example: ```toml [[example]] name = "device" required-features = ["blocking"] path = "examples/blocking/device.rs" ``` - [x] device - [x] artist_top_tracks - [x] categories - [x] current_playback - [x] current_playing - [x] current_user_followed_artists - [x] current_user_playing_track - [x] current_user_playlists - [x] current_user_recently_played - [x] current_user_saved_albums_add - [x] current_user_saved_albums_contains - [x] current_user_saved_albums_delete - [x] current_user_saved_albums - [x] current_user_saved_tracks_add - [x] current_user_saved_tracks_contains - [x] current_user_saved_tracks_delete - [x] current_user_saved_tracks - [x] current_user_top_artists - [x] current_user_top_tracks - [x] featured_playlists - [x] me - [x] new_releases - [x] next_playback - [x] pause_playback - [x] playlist - [x] previous_playback - [x] recommendations - [x] repeat - [x] search_album - [x] search_artist - [x] search_playlist - [x] search_track - [x] seek_track - [x] shuffle - [x] start_playback - [x] transfer_playback - [x] user_artist_check_follow - [x] user_follow_artists - [x] user_follow_users - [x] user_playlist_add_tracks - [x] user_playlist_change_detail - [x] user_playlist_check_follow - [x] user_playlist_create - [x] user_playlist_follow_playlist - [x] user_playlist_recorder_tracks - [x] user_playlist_remove_all_occurrences_of_tracks - [x] user_playlist_remove_specific_occurrenes_of_tracks - [x] user_playlist_replace_tracks - [x] user_playlist - [x] user_playlists - [x] user_playlist_tracks - [x] user_playlist_unfollow - [x] user_unfollow_artists - [x] user_unfollow_users - [x] volume
kerem 2026-02-27 20:22:39 +03:00
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#23
No description provided.