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