npm.io
1.0.3 • Published 4 years ago

foreach-sync-callback

Licence
ISC
Version
1.0.3
Deps
0
Size
1 kB
Vulns
0
Weekly
0

for-each-sync-callback

- This npm module provides you synchronize callback forEach function

Install

- npm install foreach-sync-callback

Test

const forEachSyncCallBack = require('foreach-sync-callback')

let arr = [1, 2, 3, 4, 5, 6, 7]

// You have to pass array and callback function into this function
// Callback function has parameter in below sequence
// 1. res 2. element 3. element Index 4. array
forEachSyncCallBack(arr, (res, e, i) => {
    // Adding time out to check sync forEach

    setTimeout(() => {

        console.log(e)

        //You must have to call "res()" at end of your callback function
        res()
    }, 1000);
})

// Function will print all element one by one in console after 1 sec

Keywords