Jump to content
McKay Development

Recommended Posts

Posted (edited)

Hello , I try to get the price of each item, but I do not have time to do it, and I return the undefined . How i can get price of each items ?

My code

---

resolve it with promise

close theme please 

Edited by Ino
  • 1 month later...
Posted

Hello , I try to get the price of each item, but I do not have time to do it, and I return the undefined . How i can get price of each items ?

My code

---

resolve it with promise

close theme please 

would you mind how you managed to solve the problem.

Posted

would you mind how you managed to solve the problem.

The async nodeJS module is also a good alternative if you don't want to use promises. They're basically the same thing except it makes code a lot neater.

Posted

he already said using promises. Youve gotta learn how to use promises for async functions

The Promise is the easy part that's not what I was getting at. The issue I have is I can't slow it down for rate limit so I'm wondering how he managed that.

  • 2 weeks later...
Posted (edited)

The Promise is the easy part that's not what I was getting at. The issue I have is I can't slow it down for rate limit so I'm wondering how he managed that.

   
 community.getUserInventory(steamid, 730, 2, true, function(err, inventory) {
        if( inventory !== undefined ) {
            let items = inventory.map( (item, idx) => {
               return new Promise((resolve, reject) => {
                  community.getMarketItem(730, item.market_name, function(err, items) {
                      if (err) {
                          console.log(err);
                          resolve([])
                      } else {
                         resolve(items.lowestPrice)
                      }
                  });
              }).then( price => {
                   return {
                      name: item.market_name,
                      assetsId: item.assetid,
                      iconUrl: (item.icon_url_large == undefined) ? item.icon_url : item.icon_url_large,
                      price: price / 100
                  }
              })
        })
            Promise.all(items).then( result => {
          // Do this something
              })
}
Edited by Ino
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...