This depends on the type of pill you are taking, but there are a few good rules to follow. You may also want to talk with your doctor when your medication is prescribed, in case something like this happens.
Less than 30 minutes after - take the pill again (this is what should happen in the situation you described)
More than 90 minutes after - definitely don't take the pill again; it has probably gone past your stomach
30-60 minutes after - if the risk of taking the pill outweighs the benefits, take the pill; if unsure, contact your doctor
60-90 minutes after - usually don't take the pill, unless the pill is really, really important; again, if unsure, contact your doctor
These numbers are more of an estimate, combined from numbers taken from several sources.
Note: this can vary from pill to pill, so it is best to call your doctor
What To Do If You Vomit After Taking Your Medication
Azithromycin
Vomiting of Oral Medications by Pediatric Patients: Survey of Medication Redosing Practices