Coder Social home page Coder Social logo

Comments (12)

julien-c avatar julien-c commented on May 28, 2024 3

Also +1 for native Promise support in this library. It's 2019 guys! Everyone uses Promises now.

from vonage-node-sdk.

AlexLakatos avatar AlexLakatos commented on May 28, 2024 3

I'm going to do a re-write this year, and promises are on my list of features to add with the rewrite.

from vonage-node-sdk.

AlexLakatos avatar AlexLakatos commented on May 28, 2024 1

@leggetter to support both, I only know of nodeify, and that's not the easy way. I would suggest people use bluebird's Promise.promisifyAll on importing the module, that should do the trick.

from vonage-node-sdk.

rlancer avatar rlancer commented on May 28, 2024

I would suggest if there is no callback to return a promise

from vonage-node-sdk.

leggetter avatar leggetter commented on May 28, 2024

@AlexLakatos - Do you have any thoughts on a recommended approach. Do we simply recommend using someLibrary.promisify or is there a way of us easily adding Promise support to the library?

from vonage-node-sdk.

shide1989 avatar shide1989 commented on May 28, 2024

There's a library called bluebird, which seems to be widespread and maintained (that I personally always use), i would recommend using it : https://github.com/petkaantonov/bluebird
the api documentation is available here : http://bluebirdjs.com/docs/api-reference.html
finally, adding promises nearly always consists of :

const Promise = require('bluebird');

function myPromiseCall(param) {
  return new Promise(resolve, reject) {
    someAsyncCall(param, function(err, result){
      if(err){
        if(callback) callback(err);
        return reject(err);
      }
      if(callback) callback(null, result);
      resolve(result);
    });
  };
}

adding this support at your top level functions (like request calls) simplifies the whole callback/result management inside the api. once you start using them, you get out of all the callback hell

from vonage-node-sdk.

shide1989 avatar shide1989 commented on May 28, 2024

@AlexLakatos it could be a good solution, but would require exhaustive testing though

from vonage-node-sdk.

machinshin avatar machinshin commented on May 28, 2024

any update on this?

from vonage-node-sdk.

AlexLakatos avatar AlexLakatos commented on May 28, 2024

There are no plans to add promise support in the near future. bluebird worked well for me over these last few weeks though. @machinshin I would suggest you give that a try.

from vonage-node-sdk.

bidah avatar bidah commented on May 28, 2024

I solved it this way:

first I made this function wrapper around nexmo.verify.request

  verifyRequest(number, callback) {
    nexmo.verify.request(
      {
        number,
        brand: "Haip"
      },
      callback
    );
  }

Then you can wrap the function in a function that returns a promise like so:

function verifyRequestPromise(phone) {
  return new Promise(function(resolve, reject) {
    verifyRequest(
      phone,
      (err, result) => (Boolean(err) ? reject(err) : resolve(result))
    );
  });
}

from vonage-node-sdk.

fauna5 avatar fauna5 commented on May 28, 2024

Also with util.promisify in Node 8+
Docs -> https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original

const util = require('util');

const verifyRequestPromise = util.promisify(nexmo.verify.request.bind(nexmo.verify));

const result = await verifyRequestPromise({
  number,
  brand: "Haip"
})

from vonage-node-sdk.

kellyjandrews avatar kellyjandrews commented on May 28, 2024

Merge with #294

from vonage-node-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.