pepzwee / node-csgo-web-tradebot

Web based CS:GO trade bot. Similar to CSGOSell.
MIT License
147 stars 59 forks source link

Loading user inv after the bot inv is fully loaded #153

Closed Vlady17 closed 6 years ago

Vlady17 commented 6 years ago

Hey There! I know that i need to write it by my self, but I already tried so many things and can't resolve my problem...

I need to execute 'get user inv' function after the 'get bot inv' function is done (By reloading the page), because the user inv loads faster and info about overstock comes later as the bot inv is loaded.

  1. I tried to make a sleep function in index.js file. I set it between this two functions (It worked but only for both functions)

  2. I asked on stackoverflow, and some users said me to use promises. But with the promises u can't get that result...

    
    var promise1 = new Promise((resolve, reject) => {
    socket.on('get bot inv', (id) => {
        Trade.getInventory(config.bots[id].steamID64, config.appID, config.contextID, (err, data) => {
            socket.emit('bot inv', { error: err, items: data })
            resolve();
        })
    })
    })

var promise2 = new Promise((resolve, reject) => { socket.on('get user inv', (steamID64) => { Trade.getInventory(steamID64, config.appID, config.contextID, (err, data) => { socket.emit('user inv', { error: err, items: data }) resolve(); }) }) })

promise1.then(() => {return promise2});


Its making the same thing like a sleep function :(

**How can i resolve this problem? Or should I edit the app.js file?**
Vlady17 commented 6 years ago

Solved 💯

FreddyFish commented 6 years ago

Share the solution! 👍 Someone in the future might get the same problem as you, and i'm sure that would help that guy a lot!