✓ Accepted answer
In a situation like this, the first option is always going to be the best option.
The second option uses a while loop that constantly checks if the value is true. This uses up resources because you're looping 1/30th a second as well as checking if a value is true.
On the other hand, the first option uses an event which fires when the value is changed. You don't need to constantly check all the time, you just need to check when it changes.
Here's an analogy:
There's a guest coming around to your house. Are you going to constantly check the door if he/she is there while you could be preparing the house or food, etc? Or will you prepare the house/food, while waiting for the doorbell to be rang?
There's a doorbell for a reason.
1 comment
Love this example, nice.