title: Using Promises with boolean return values
body: <p>I am interested in the best implementation of a <a href="https://en.wikipedia.org/wiki/Futures_and_promises" rel="nofollow noreferrer">Promise</a> that is meant to give a boolean result. My question considers any implementation of Promises / Futures that includes a logical equivalent of <code>then</code> as in <a href="https://promisesaplus.com" rel="nofollow noreferrer">Promises/A+</a>.
  My question is: should such a Promise <code>resolve</code> with a boolean whatever the result or should it <code>resolve</code> on <code>true</code> and <code>reject</code> on <code>false</code>?</p>
  
  <p>Thus in Javascript as in <a href="http://www.ecma-international.org/ecma-262/6.0/" rel="nofollow noreferrer">ES6</a>:</p>
  
  <pre><code>class Named {
      constructor(name) {
          this.name = name;
      }
      // always resolve
      isFoo1() {
          return new Promise(resolve =&gt; {
          resolve(this.name === 'Foo');
          });
      }
      // resolve or reject
      isFoo2() {
          return new Promise((resolve, reject) =&gt; {
              if (this.name === 'Foo') {
                  return resolve(true);
              }
              reject(new Error('Not Foo!'));
          });
      }
  }
  </code></pre>
  
  <p>Now you can do:</p>
  
  <pre><code>const namedObjects = [new Named('Foo'), new Named('FooBar'), new Named('Foo')];
  const nameChecks = namedObjects.map(obj =&gt; obj.isFoo1());
  const checkNames = () =&gt; namedObjects.map(obj =&gt; obj.isFoo2());
  
  // using always resolve
  Promise.all(nameChecks)
      .then(results =&gt; {
          if(results.every(v =&gt; v)) {
              return alert('all is foo!');
          }
          alert('all is not foo!');
      });
  
  // using resolve or reject
  Promise.all(checkNames())
      .then(() =&gt; alert('all is foo!'))
      .catch(() =&gt; alert('all is not foo!'));
  </code></pre>
  
  <p>I would argue that the "resolve or reject" version works more naturally with the <code>Promise</code> concept - in particular using extended implementations as in <a href="http://bluebirdjs.com/docs/getting-started.html" rel="nofollow noreferrer">Bluebird</a>.</p>