1.2.4 • Published 6 years ago

asynciteratorjs v1.2.4

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

AsyncIterator

This library is designed to implement a sequential iteration with the ability to use async functions within iterative functions.

Examples

let AsyncIterator = require('asynciteratorjs')
    
let sleep = ms => {
    return new Promise(resolve => { setTimeout(resolve, ms) })
}
    
async function main() {
    let iterator = new AsyncIterator([1, 2, 3, 4])
    let array = []
        
    await iterator.iterate(async (value, key, dataset) => {
        await sleep(value * 1000)
            
        array.push({ key, value })
    })
    
    // After 10 seconds (because of sleep function)
    console.log(array) // [{ key: 0, value: 1 }, { key: 1, value: 2 }, { key: 2, value: 3 }, { key: 3, value: 4 }]
}
    
main()

Docs

new AsyncIterator(Elements)

Constructor of Async Iterator

ParamTypeDescription
ElementsArrayDataset array

asyncIterator.push(Elements)

Pushing new elements to iterator data storage

Kind: instance method of AsyncIterator

ParamTypeDescription
ElementsArrayNew dataset array

asyncIterator.reset()

This function is resetting data storage

Kind: instance method of AsyncIterator

asyncIterator.iterate(func, another)

This function is iterating dataset

Kind: instance method of AsyncIterator

ParamTypeDefaultDescription
funcPromiseIteration function
anotherBooleanfalsePrivate variable

Iteration function(value, key, array)

ParamTypeDescription
valueAnyIteration value
keyNumberIteration key
arrayArrayIteration dataset
1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.0.0

6 years ago