AngularJS: $q.race() in old angular versions
<p>Angular 1.5.8 implements a <code>$q.race()</code> method which takes an array of promises and returns a promise which is resolves with the value of the first resolved promise.</p>

<p>However i am stuck with angular 1.4 for now and need some kind of functionality like a <code>$q.any</code> or <code>$q.race</code> method.</p>

<p>Currently I use flags inside <code>.then()</code> to "remember" the state of promises which obviously is not ideal.</p>

<pre><code>var resolvedPromise = null;

promise1.then(function(data){
  if(!resolvedPromise === 'promise2'){
    resolvedPromise = 'promise1';
    successcallback(data)
  }
})

promise2.then(function(data){
  if(!resolvedPromise === 'promise1'){
    resolvedPromise = 'promise2';
    successcallback(data)
  }
})
</code></pre>

<p><strong>Question</strong></p>

<p>I only need this to work for two promises at a time: </p>

<pre><code>myRaceFkt(p1,p2)
  .then(successcallback)
</code></pre>

<p>Is there a more elegant solution without having access to the improved <code>$q</code>-api of 1.5.8?</p>