There are much more effective ways of setting a boundary than that. In this case, Person A (or anyone who is criticizing, name-calling, etc) is unconscious and is not open to hearing or responding to what Person B does or says.

It is far more effective to validate first until they become conscious, then the boundary can be set firmly - and because they are then conscious, they will be open to actually receiving it.

Someone who is so unconscious as to be calling another person an idiot is likely to react negatively to also being called abusive.

By walking away or immediately reacting with the "limit," there is no opportunity for this. My experience has been that it is much more effective to validate the other person first and then set a limit.