s
s
snc
Search…
forSync
snc.forSync(initial, final, increment, callback_loop(index, next, end), callback_end(data))
Syncronous "for" iterator. Alternative name: for.
1
snc.for(0, 10, 1, (index, next, end) => {
2
console.log(index)
3
setTimeout(() => {
4
next(5)
5
}, 1000)
6
}, data => {
7
console.log(`LENGTH: ${data.length} -> ${JSON.stringify(data)}`)
8
})
Copied!
1
-> 0
2
-> 1
3
-> 2
4
-> 3
5
-> 4
6
-> 5
7
-> 6
8
-> 7
9
-> 8
10
-> 9
11
-> LENGTH: 10 -> [5,5,5,5,5,5,5,5,5,5]
Copied!
1
snc.for(1, 10, 2, (index, next, end) => {
2
console.log(index)
3
setTimeout(() => {
4
next(index)
5
}, 1000)
6
}, data => {
7
console.log(data)
8
})
Copied!
1
-> 1
2
-> 3
3
-> 5
4
-> 7
5
-> 9
6
-> [ 1, 3, 5, 7, 9 ]
Copied!
Copy link