title: Given an array; how do I run a function for the first element and conditionally wait, return, or run the function for the next element?
body: <p>I have set of functions on Parse Cloud that query a node/mongo API that I have running externally.</p>
  
  <p>One of these functions gives me an array of active user objectIds, each of which map to a message channel name ordered by distance.</p>
  
  <p>I need to take this array of objectIds and starting with the first element:</p>
  
  <ol>
  <li>Send a message;</li>
  <li>Set a timeout (I'll try 30 seconds while testing, but could be anything greater in prod);</li>
  <li>If, during the timeout I receive an 'unavailable' response then ditch the remaining time, move on to the next element and go back to 1;</li>
  <li>If, during the timeout I receive an 'available' response, then exit the loop, forget about all the other elements and return success.</li>
  <li>If I get no responses at all, return failure.</li>
  </ol>
  
  <p>I'm not sure if Parse CloudCode is the right tool for this job so I've tagged node in case I need to put the logic in the API instead.</p>
  
  <p>JS is still young in this one so answers that have a bit of depth or allow me to learn something that will answer my question are appreciated and upvoted.</p>