Having been involved (in my youth) in training working dogs (some of the work was attack/protection work) I'm pretty confident that a stun gun (electric shock... not to be confused with an actual Taser's embedded barbs) is as likely to increase the attack/prey behavior as to dissuade it. To make shock work you have to time it to just BEFORE the animal is committed to the attack. If he's already on the way, I wouldn't shock. Truly most of them don't "stun" they shock/hurt. I've seen this further enrage an attacking dog.
OC spray, I think, is a better bet. Pain isn't the only consequence: vision and breathing effects also ensue. I'd buy a small canister of Bear Spray if I were that concerned about dog attack. By the way:some come with warnings "Not to be used on humans"..... but any thug attacking one of us is not, in my judgment, human.