This is an extremely dangerous situation that should be obviously avoided at all costs. Should you ever find yourself at gunpoint, do everything reasonably possible to accommodate the aggressor.
However, if the situation calls for it, it is best to be prepared through training of solid techniques like these for gaining control of the weapon. These are some of the most fundamentally solid methods for disarms I have ever trained that I am sharing here.
Train smart and safely, and do everything you can to avoid ever being in situations like the ones I reference in this video.