Closed ramsayleung closed 1 year ago
I have some tests written as well https://github.com/PaulOlteanu/rspotify/commit/2d38341478bfa950225a2fbd8e6e5d6ddcb4c5ac if you'd like to add those
Thanks for your contribution, I would like to add your test, but I refine the callback function based your code.
The callback function is a field of Config
struct instead of SpotifyClient
, so it's unnecessary to use Arc<Mutex>
to sync between different threads.
TokenCallback
should only be invoked when a token is gained successfully, so it's unnecessary to use Fn(Option<Token>
, Fn(Token)
is more appropriate.
Furthermore, the callback function might throw an error, so the return value of the callback function should be Result
Yeah I had them written up for my original implementation - I just added them in case you wanted to modify them to fit this pr
Sure, thanks for your contribution in advance.
Description
Add a user-customized callback function support which is invoked whenever client succeeds to request or refresh a token, so it provides users an opportunity to save token into file, store into database etc.
Motivation and Context
400
Dependencies
None
Type of change
Please delete options that are not relevant.
How has this been tested?
with_token_callback_fn.rs
Is this change properly documented?
Please make sure you've properly documented the changes you're making.
Don't forget to add an entry to the CHANGELOG if necessary (new features, breaking changes, relevant internal improvements).