Whenever this happens, it’s a good idea to take some time to relax. You don’t need to distance yourself from the game, just don’t let your emotions get the better of you. Cash out if possible and look for other activities to distract yourself a bit.
-snip-
Discipline yourself.
It is seen that it is easier said than done. In my case I don't usually let myself get carried away by my emotions when I narrowly lose, but even I have to admit that sometimes I allow myself one or two more tries, being very aware that this is an exception, to avoid making it an habit.
Others may not see anything wrong with doing so, or may convince themselves about it, but like my colleagues above I'd always recommend to control your impulses when it comes to gambling.