Unless you're completely lacking situational awareness, I imagine the gun would come into play shortly before one was under attack.
Once I walking back from the library at 2 in the morning (just finished a long study session), and passed by two black stereotypes (baggy pants, hoodies, etc) on my way back. Didn't think much of them at first, but they reacted rather strangely to me. First they glanced at me for longer than usual, then they looked at each other, then they slowed down and let me pass.
I continued walking, took a right turn, crossing a street in the process. They noticeably and somewhat awkwardly cut the corner to follow me. At this point they were about 25 feet behind me. Then about 15 seconds after we'd completed the turn, they spontaneously doubled the pace and started to close. I held my pace steady, turned my head 90 degrees to let them know I'd seen them, and made a show of shoving my hands in my pockets. They SLAMMED on the brakes and dropped back to about 50 feet. Didn't bother me for the remainder of my walk home.
This was on a route I'd walked literally 1000 times before without issue, and the mere threat of a weapon was enough to stop them. I wonder how effective that threat would have been if our gun/knife laws were more restrictive.