Skip to content

Tidy async/await solution for avoiding callback hell #1092

@ghost

Description

For anyone using modern browsers/node, this should help to make the examples usable.

The secret lies in util.promisify!

const util = require('util')
const dbAccessToken = 'YOURTOKEN'
const dropbox = require('dropbox-v2-api').authenticate({ token: dbAccessToken })
const dbSync = util.promisify(dropbox)

async function getAcc () {
  const params = { resource: 'users/get_current_account' }
  try {
    return (await dbSync(params))
  } catch (err) {
    console.error(err)
  }
}

async function test () {
  console.log(await getAcc())
}

test()

Hope this helps someone else avoid a good couple of hours struggling with why the "returns" were returning" undefined"!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions