1 Preface
Today, I am exited to introduce you the v0.9 release I have been continued to work on it for the past few weeks that
adds async/await support now!
2 The road to async/await
What is rspotify: > For those who has never heared about rspotify before, rspotify is a Spotify web Api wrapper implemented in Rust.
With async/await’s forthcoming stabilization and reqwest adds
async/await support now, I think it’s time to let rspotify leverage
power from async/await. To be honest, I was not familiar with
async/await before, because of my Java background from where I just
get used to multiple thread and sync stuff(Yes, I know Java has future
either).
After reading some good learning resources, such as Async book, Zero-cost Async IO, I
started to step into the world of async/await. async/await is a way
to write functions that can “pause”, return control to the runtime, ant
then pick up from where they left off.
I think perhaps the most important part of async/await is runtime, which defines how to
schedule the functions.
Now, by leveraging the async/await power of reqwest, rspotify could
send HTTP request and handle response asynchronously.
Futhermore, not only do I refactor the old blocking endpoint functions to async/await
version, but also keep the old blocking endpoint functions with a new
additional feature blocking, then other developers could choose API to
their taste.
3 Overview
album example:
| |
Just change the default API to async, and moving the previous
synchronous API to blocking module.
Notes that I think the v0.9 release of rspotify is going to be a huge
break change because of the support for async/await, which definitely
breaks backward compatibility.
So I decide to make an other break change into the next release, just refactoring the project structure to shorten the import path:
before:
| |
after:
| |
the spotify module is unnecessary and inelegant, so I just remove it.
4 Conclusion
rspotify v0.9 is now available! There is documentation, examples and an issue tracker!
Please provide any feedback, as I would love to improve this library any way I can! Thanks @Alexander so much for actively participate in the refactor work for support
async/await.