Back to problems

First Successful Concurrent API Call Within a Timeout

Object-Oriented Programming · Apple · Medium

Event-Queue Simulation When every call is launched at the same instant, the only thing that decides the order in which results arrive is each call's delay. So rather than spawning real threads and sleeping, we can replay the timeline deterministically: put every call into a min-heap keyed by its completion time, then pop completions in chronological order exactly the way an event loop would deliver them. The first popped event that is a success wins; every later event is…

Loading the rest of the question…