title: Async operations inside indexeddb cursor
body: <p>I'm using <strong>indexedDB</strong> Promised library to convert the <strong>indexedDB API</strong> to promises. </p>
  
  <p>Looks like by the time my fetch is completed my indexed db transaction is no longer active. I'm guessing it is timing out?</p>
  
  <p>The error I get is:</p>
  
  <p><code>DOMException: Failed to execute 'delete' on 'IDBCursor': The transaction has finished.</code></p>
  
  <p>What I'm trying to accomplish is to delete the item from <code>indexedDB</code>, only and only if the fetch is completed successfully. I understand that I can create a second transaction after the fetch to get the item and remove it. But I'm wondering if there's a better way without doing a new transaction? Am I missing something?</p>
  
  <p>Can anyone explain to me why I'm seeing this problem?</p>
  
  <pre><code>DBHelper.DBPromised.then( db =&gt; {
    const store = db.transaction('deferredReviews', 'readwrite').objectStore('deferredReviews');
    const submittedRes = {};
    store.openCursor()
      .then(function submitAndDelete(cursor) {
          if (!cursor) return;
          console.log(cursor.value);
  
          fetch(`${DBHelper.DATABASE_URL}/reviews`, {
            method: 'POST',
            body: JSON.stringify({
              restaurant_id: cursor.value.restaurant_id,
              name: cursor.value.name,
              createdAt: cursor.value.deferredAt,
              rating: cursor.value.rating,
              comments: cursor.value.comments
            })
          })
          .then(response =&gt; {
            if (!response.ok) {
              throw Error(response.statusText);
            }
            return response.json();
          })
          // If response is ok then delete from indexedDB.
          .then(review =&gt; {
            if (!review) return new Error('Could not submit');
            if (cursor.value.restaurant_name in submittedRes) {
              submittedRes[cursor.value.restaurant_name] = submittedRes[cursor.value.restaurant_name] + 1;
            } else {
              submittedRes[cursor.value.restaurant_name] = 1;
            }
            cursor.delete();
            return cursor.continue().then(submitAndDelete);
          });
      })
      .then(() =&gt; {
        if (Object.keys(submittedRes).length === 0 &amp;&amp; submittedRes.constructor === Object) return;
          DBHelper.showDeferredSubmitModal(submittedRes);
      });
  });
  </code></pre>