1.1.0 • Published 4 years ago
asynkron v1.1.0
Asynkron :
asynkron is utility module to make async loops and reduces
Features :
very very small
No ( Maximum call size ) error
you can break loop
you can change key name of object
specify result type Array / Object
it used by qlink(https://www.npmjs.com/package/qlink-server and qreal(https://www.npmjs.com/package/qreal
Install :
just require it in node environment but in browser environment use unpkg src
<script src='https://unpkg.com/asynkron'></script>
Usage :
just pass Array / object what you want to make loop
asynkron return promise so you can use async / await with it
const asynkron = require('asynkron');
const fs = require('fs');
asynkron(['./file1', './file2', './file3'], (filepath, index, done, result) => {
// done( item, index? )
fs.readFile(filepath, (err, file) => {
if ( err ) {
// pass item and index false to break loop
done(false, false)
} else {
done(file)
}
})
}).then(files => console.log( files ))
to use asynkron with object and change key name of it just pass result value
const asynkron = require('asynkron');
const fs = require('fs');
asynkron(['./file1', './file2', './file3'], (filepath, index, done, result) => {
// done( item, index? )
fs.readFile(filepath, (err, file) => {
if ( err ) {
// pass item and index false to break loop
done(false, false)
} else {
done(file, filepath)
}
})
}, {} /* Result */ ).then(files => console.log( files ))
// asynkron will resolve
{
'./file1' : { ... },
...
}