question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promise seems to be not working

See original GitHub issue

Hello,

It seems the async/await pattern is not working.

  const { request_id: requestId, status, error_text: errorText } = await nexmo.verify.request({
      number: `639151112233`,
      brand,
      code_length: 6,
      format: 'json',
    });

Only the callback pattern is working. Is this a bug or just not supported? Thanks a lot.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
fauna5commented, Jul 31, 2018

In the meantime you could always wrap the API using promisify (requires Node 8+) https://nodejs.org/dist/latest-v8.x/docs/api/util.html

Here’s an example using the sendSms API

const util = require('util');
...
const sendSms = util.promisify(
  nexmoClient.message.sendSms.bind(nexmoClient.message),
);

async function sendMessage() {
  try {
    await sendSms('bob', TO_NUMBER, 'hello');
    console.log('success!');
  } catch (error) {
    console.log('sad face');
  }
}

sendMessage();
0reactions
soullivaneuhcommented, Jul 11, 2020

Unfortunately only callbacks are supported at the moment. We’ll be working on a promise based library later this year

Using Promise as default is quite a must have to avoid some hacks like https://github.com/Nexmo/nexmo-node/issues/197#issuecomment-409252927 (thanks @arvi BTW!).

Could we re-open the issue until this got implemented?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why "this" seems not working to resolve a promise on load event
Having the following javascript Promise code: const loadImage = (src) => new Promise((resolve, reject) => ...
Read more >
The Problem with Promises in JavaScript - DEV Community ‍ ‍
Promises lack a convenient API to safely work with data.​​ This second case is a problem only because the promise API doesn't offer...
Read more >
God's Promise to Hagar: Clearing up a misunderstanding
But this is not all God does. He promises her a multitude of descendants. It appears that God is coming alongside Hagar to...
Read more >
How to use promises - Learn web development | MDN
A promise is an object returned by an asynchronous function, which represents the ... "promise" is a Promise object, so this will not...
Read more >
broken promise collocation | meanings and examples of use
Examples of broken promise in a sentence, how to use it. 20 examples: Is it yet another broken promise to add to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found