What is the ideal timing for endoscopy in acute upper gastrointestinal bleeding?

What is the ideal timing for endoscopy in acute upper gastrointestinal bleeding?