Fall back to a defensible choke point and ambush him. First strike is something blunt to either the kidneys or skull, next is a supinating wristlock on his weapon hand; break his finger in the trigger guard, take it away from him. Strip the weapon and restrain him until police arrive.
It also depends on the weapon. If it's some punk with a knockoff 9mm Glock, I'd be more inclined to act sooner rather than later. But if he's got a Colt 45, or a heavy revolver, I'll wait because those weapons just have more killing potential.
As a side note: A local restaurant here got robbed by a gunman wielding an semi-automatic pistol with the slide locked back. That means that the magazine is EMPTY. That means you smack him with the cash drawer.