F
F
flafy42020-01-16 16:19:00
JavaScript
flafy4, 2020-01-16 16:19:00

How to get result from Promise?

Hello.
The following structure does not work:

async function openDb() {
      return await window.indexedDB.open('test1', 1)
  }

  openDb().then(data => {
    console.log(data.result)
  }).catch(e => {
    console.log(e)
  })

Mistake:
Failed to read the 'result' property from 'IDBRequest': The request has not finished.

BUT it works like this:
async function openDb() {
      return await window.indexedDB.open('test1', 1)
  }

  openDb().then(data => {
    setTimeout(function() {
      console.log(data.result)
    }, 1000)
  }).catch(e => {
    console.log(e)
  })

How to remove the crutch in the form of setTimeout and make this case return result to me?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question