News for hackers. Stuff that matters.
Re:Node v7.5.0 Released by egeozcan on Friday February 03, 2017 @08:02AM (#13559480)
You can take the part before `.then()` and pass it around.
Re:Node v7.5.0 Released by woudsma on Friday February 03, 2017 @08:09AM (#13559517)
yes that works quite great. you have to define a 'async' function, in which you can use the 'await' keyword.

async getDoc(doc) {

  const result = await db.get(doc)

  console.log('result:', result)
}

// instead of:

function getDoc(doc) {

  db.get(doc, result => {
    console.log('result:', result)
  });
}

// or

function getDoc(doc) {

  db.get(doc)
    .then(result => 'result: ' + result)
    .then(::console.log)
    .catch(::console.error)

}