s
s
snc
Search…
⌃K

each

snc.each(iterable_array, callback_loop(item, index, next_method, end_method), callback_end(data))
Runs next function when "next" method is executed.
const list = ['a', 'b', 'c']
snc.each(list, (item, index, next, end) => {
console.log(`item: ${item}`)
setTimeout(next, 3000)
},
() => {
console.log(`End`)
})
-> item: a // Wait 3 seconds
-> item: b // Wait 3 seconds
-> item: c // Wait 3 seconds
-> End
Call "end" method for break the loop.
const list = ['a', 'b', 'c'];
snc.each(list, (item, index, next, end) => {
console.log(`item: ${item}`)
setTimeout(() => {
if (index === 1) end(`Bye!`)
else next()
}, 3000)
}, data => {
if (data) console.log(`End: ${JSON.stringify(data)}`)
else console.log(`End`)
});
-> item: a // Wait 3 seconds;
-> item: b // Wait 3 seconds;
-> End: Bye!