Skip to content

Instantly share code, notes, and snippets.

@igordata
Last active September 15, 2020 21:37
Show Gist options
  • Save igordata/6ed179dcc114ea806b027ac838be2d55 to your computer and use it in GitHub Desktop.
Save igordata/6ed179dcc114ea806b027ac838be2d55 to your computer and use it in GitHub Desktop.
promise fight
class Aaa {
loadTXs(txs, steps = 0) {
const rs = []
for (const tx of txs) {
const r = this._loadTX(tx)
if (r === null) continue
r.then((result) => {
this.$store.dispatch('rawDataAdd', result)
return this._analyseAndRepeat(result, tx, steps)
})
rs.push(r)
}
Promise.all(rs).then((values) => console.log('все промисы отработали', values))
}
_loadTX(tx) {
if (!tx) return null
return this.API.loadTX(tx)
}
_analyseAndRepeat(dataEntries, tx, counter = 30) {
if (counter < 1) return null
/* тут логика, часть кода пропущена, но суть - randomSrting берется из dataEntries и дальше всё по новой */
const p = this._loadTX(randomSrting)
if (p === null) return null
p.then((result) => {
return this._analyseAndRepeat(result, randomSrting, --counter)
})
return p
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment