Demand they leave, or you leave quickly and call the police. Have your key ready before you reach the door-home, car, office, or dorm. Keep your car in good shape with plenty of gas in the tank. Use your head to protect your body. Calm down - play for time.
Every situation is different - there are no easy answers.
Know yourself and your capabilities. Assess the circumstances - look for an out. Try to read the rapist - motivation, personality, what might work to get away . Do Not shower, bathe or douche, or throw any clothing away. Call a friend, or your rape crisis center.