The OpenD Programming Language

waitForFirstToComplete

Waits for the first of the given requests to be either aborted or completed. Returns the first one in that state, or null if the operation was interrupted or reached the given timeout before any completed. (If it returns null even before the timeout, it might be because the user pressed ctrl+c, so you should consider checking if you should cancel the operation. If not, you can simply call it again with the same arguments to start waiting again.)

You MUST check for null, even if you don't specify a timeout!

Note that if an individual request times out before any others request, it will return that timed out request, since that counts as completion.

If the return is not null, you should call waitForCompletion on the given request to get the response out. It will not have to wait since it is guaranteed to be finished when returned by this function; that will just give you the cached response.

(I thought about just having it return the response, but tying a response back to a request is harder than just getting the original request object back and taking the response out of it.)

Please note: if a request in the set has already completed or been aborted, it will always return the first one it sees upon calling the function. You may wish to remove them from the list before calling the function.

  1. HttpRequest waitForFirstToComplete(Duration timeout, HttpRequest[] requests)
  2. HttpRequest waitForFirstToComplete(HttpRequest[] requests)
    waitForFirstToComplete

Meta

History

Added December 24, 2021 (dub v10.5)