Pybites Logo

Pomodoro with asyncio

Level: Advanced (score: 4)

This Bite explores asyncio and type-hinting.

For this bite, you will be taking a simple Pomodoro timer and refactoring it to utilize asynchronous coroutines with the async and await keywords. You will also need to add type hinting to the code.

It's not the best example of it, but it will give you some hands on practice with how it flows together. The pomodoro code works as is, but the tests will be calling the functions with the async keyword.

The code outputs the following with the dummy data:

Pomodor timer started at: 22:13:56

Session: 1
[1] 22:13:56 Time to work!
[1] 22:13:56 Time for a 0 min break!
[2] 22:13:56 Time to work!
[2] 22:13:56 Time for a 0 min break!
[3] 22:13:56 Time to work!
[3] 22:13:56 Time for a 0 min break!
[4] 22:13:56 Time to work!
[4] 22:13:56 Time for a 0 min break!

Session: 2
[1] 22:13:56 Time to work!
[1] 22:13:56 Time for a 0 min break!
[2] 22:13:56 Time to work!
[2] 22:13:56 Time for a 0 min break!
[3] 22:13:56 Time to work!
[3] 22:13:56 Time for a 0 min break!
[4] 22:13:56 Time to work!

** 22:13:56 Time for lunch! **

Session: 3
[1] 22:13:56 Time to work!
[1] 22:13:56 Time for a 0 min break!
[2] 22:13:56 Time to work!
[2] 22:13:56 Time for a 0 min break!
[3] 22:13:56 Time to work!
[3] 22:13:56 Time for a 0 min break!
[4] 22:13:56 Time to work!
[4] 22:13:56 Time for a 0 min break!

Session: 4
[1] 22:13:56 Time to work!
[1] 22:13:56 Time for a 0 min break!
[2] 22:13:56 Time to work!
[2] 22:13:56 Time for a 0 min break!
[3] 22:13:56 Time to work!
[3] 22:13:56 Time for a 0 min break!
[4] 22:13:56 Time to work!

22:13:56 Time to go home!

Work day completed at: 22:13:56

If run with the commented code, it would take about 8 hours to complete!

Have fun!