t3chnoboy / amazon-product-api

:credit_card: Amazon Product Advertising API client
365 stars 104 forks source link

sync response #79

Closed akelmj closed 7 years ago

akelmj commented 7 years ago

when i call this function i get: undefined

for example:

var r = amazonGetItem('B002SSUQFG');

function amazonGetItem(asin) {
    var result;
    client.itemLookup({
        idType: 'ASIN',
        itemId: asin
    }).then(function (results) {
        result = results;
    }).catch(function (err) {
        console.log(err);
      result = '';
    });
    return result;
}

i want to wait untill the temLookup return data?

thanks.

masterT commented 7 years ago

Yes, because you returned the result value before it was assigned in the Promise.

masterT commented 7 years ago

There is a lot of asynchronous computations in javascript and nodejs. I recommend you to get familiar with it!

akelmj commented 7 years ago

thanks.