Skip to content

Instantly share code, notes, and snippets.

@ErickWendel
Created July 11, 2017 19:48
Show Gist options
  • Select an option

  • Save ErickWendel/bcc47219dd13c62d203aed8a8df91875 to your computer and use it in GitHub Desktop.

Select an option

Save ErickWendel/bcc47219dd13c62d203aed8a8df91875 to your computer and use it in GitHub Desktop.
class Process {
chunk(leads, count) {
const X = count;
return leads.reduce((ar, it, i) => {
const ix = Math.floor(i / X);
if (!ar[ix]) ar[ix] = [];
ar[ix].push(it);
return ar;
}, [])
}
makeU(index, arrays) {
let promises = arrays[index].map(items => {
console.log('processed', items)
return new Promise((resolve) => resolve(items))
})
return Promise.all(promises)
}
stackUpdate(leads) {
const that = this
const chunkCount = 1
let arrays = this.chunk(leads, chunkCount)
let totalCount = arrays.length
console.log('>>> chunk', chunkCount, '')
console.log('>>> totalCount', totalCount, '\n')
let indexI = totalCount - 1
if (indexI == 0) return that.makeU(indexI, arrays)
let total = indexI
let promises = []
console.log('arrays', arrays, '\n')
let executados = []
const run = arrays.length
for (let i = 0; i < run; i++) {
let promise1 = that.makeU(i, arrays)
promises.push(promise1)
}
let strings = []
for (let i = 0; i < run; i++) {
const promises1 = `promises[${i}].then(_ => promises[${i + 1})`
strings.push(promises1)
i += 1
}
eval(strings)
}
}
new Process().stackUpdate(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment