Usage of async/await instead of promise/then #3739
milanholemans
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Few days ago, we merged a PR to rework the entire code base of the CLI for Microsoft 365. This allowed us to step away from promise/then and embrace async/await. The reason this took so long was because our code coverage tool didn't support async/await yet, but finally it does!
What is different now?
The header of our commandAction function changed from void to Promise. This means that we can also drop our callback function (cb() at the end of every command to notify the command ended). Because commandAction returns a Promise now, we can finally use async/await in our CLI commands! This makes our code a lot more readable and less complex.
You will see that all commands use async/await right now in their commandAction. Other functions in the command still use the promise/then structure which leaves the CLI in a kind of hybrid state. This is only temporary, when v6 is released we will start refactoring all functions and tests to async/await.
What should I pay attention to?
We ask all our contributors to embrace async/await and drop promise/then. We will only accept PRs with async/await functions and tests (yes also your tests should use async/await 🙂 ). When you are creating or updating a command, we ask you to keep this in mind. Save yourself time and write everything in async/await right away so you don't have to refactor it.
Have fun coding, hope to see your async/await PRs soon in GitHub!
Beta Was this translation helpful? Give feedback.
All reactions