I (and many/{all} of us) had exactly that question.
Happily, interrupts were made for that, reacting at specific realtime events, such as: -A/D activity, USART I/O, QEI, Timers, Capture, Keyboard, switch, and so on.-

There are 2 ways to handle interrupts:
1.- The standard way is using 'ON INTERRUPT' statement & stuff. (see manual/forum)
2.- The recommended way is using Darrel Taylor's 'Instant Interrupts', once you understand it, you'll enjoy it's benefits. (documentation in a thread in the forum).

My personal choice is labeling tasks to optimize troubleshooting (if happen), code and memory. (why labeling? because PBP doesn't allow functions or sub/procedures structure)

Rodrigo.