This situation occurred with the ambidextrous pitcher Pat Venditte. He has a glove that can be worn on either hand. He faced a switch-hitter, and he and the batter kept switching sides. The video (on YouTube) is somewhat amusing.
Because of this situation, MLB added rule 8.01(f), which says, in brief, the ambidextrous pitcher chooses first, and may not change until the batter completes his plate appearance.
Official Baseball Rule 8.01(f)