Wednesday, 15 March 2017

how to call function where parameter based on a promise

had following code which worked:

let sdk = new SDK({ name: "somevalue"});

module.exports= ()=> {
  sdk.dothing();
}

I then needed to change the parameter to use data from an async function:

let asyncfunc = require('asyncfunc');

let sdk = new SDK({ name: (()=>{ 
    return asyncfunc()
        .then((data) => { 
            return data.value
        })
    });

module.exports= ()=> {
  sdk.dothing();
}

Following the change, the call to new SDK is failing because the parameter passed is {} as the asyncFunc promise has not yet resolved.

I'm getting back into node after a year and new to promises. what is the proper way to do this?



via skellish

No comments:

Post a Comment