- We are writing a digital textbook-reading app.
- You get two copies of each digital textbooks: "basic" or "enhanced." Only one computer can have the enhanced copy.
- You can only print from the enhanced copy.
- We want a simple
printAsync()
method that we can attach to our click handler.
- If the user has the basic version, we need to check if it's possible for them to upgrade to enhanced:
- If so, ask the user if they want to upgrade, and then continue the print operation.
- If not, error out: printing is impossible.
- Printing is an asynchronous operation, that could fail (e.g. if the printer is out of paper).
- Due to some horrible threaded C++ code, we get deadlocks if the user navigates through the book at the same time as the book is printing, so we need to block the UI while it prints.
I think it will look better for promises if it is kept flat like:
This should work the same if I'm not mistaken. Right now it almost looks like no callback hell was solved after all as the code keeps growing on the right...