title: Javascript promise conversion
body: <p>I'm having a hard time understanding how promises works. I've seen some examples and some of it makes sense. However, when I try to actually use it I get stuck. I have the following example:
  (I'm using q and nodejs. getItem() returns a promise, but my function doesn't wait for it.)</p>
  
  <pre><code>function calculate(id, item) {
     var calcId = id ? id : getItem(item);
     if (!id &amp;&amp; calcId) { calcId = calcId.Id; }
  
     if (calcId) {
        update(calcId);
     } else {
        insert(item);
     }
  }
  </code></pre>
  
  <p>Based on the examples, I don't see how to do it without code duplication.</p>