design for interruptable operations
- by tpaksu
I couldn't find a better topic but here it is;
1) When user clicks a button, code starts t work,
2) When another button is clicked, it would stop doing whatever it does and start to run the second button's code,
3) Or with not user interaction, an electrical power down detected from a connected device, so our software would cancel the current event and start doing the power down procedure.
How is this design mostly applied to code? I mean "stop what you are doing" part?
If you would say events, event handlers etc. how do you bind a condition to the event? and how do you tell the program without using laddered if's to end it's process?
method1();
if (powerdown) return;
method2();
if (powerdown) return;
etc.