massive async operations powered by Promise.all
Minimal async map/reduce helper with pluggable limit to handle massive amount of asynchronous operations in node and browser.
// const masynco = require('masynco') // cjs and mjs are supported
import masynco from 'masynco'
;(async () => {
// supports async and regular functions
const fn = async (num) => num + 1
// supports async array mapping
const a = await masynco([1, 2, 3], fn)
console.log(a) // [ 2, 3, 4 ]
// supports async object mapping
const o = await masynco({ 'k1': 'v1', 'k2': 'v2' }, fn)
console.log(o) // { k1: 'v11', k2: 'v21' }
// supports regular (non-async) functions also
const fnSync = (num) => num + 1
const o1 = await masynco({ 'k1': 'v1', 'k2': 'v2' }, fnSync)
console.log(o1) // { k1: 'v11', k2: 'v21' }
})()
Optionally limit
function can be passed for concurrency control:
import masynco from 'masynco'
import plimit from 'p-limit'
;(async () => {
const fn = async (num) => num + 1
const o = await masynco({ 'k1': 'v1', 'k2': 'v2' }, fn, plimit(3))
console.log(o) // { k1: 'v11', k2: 'v21' }
})()
Use in browser as JavaScript module:
<script type="module">
import masynco from './masynco.js'
;(async () => {
const fn = async (num) => num + 1
const o = await masynco({ 'k1': 'v1', 'k2': 'v2' }, fn)
console.log(o) // { k1: 'v11', k2: 'v21' }
})()
</script>
Returns a new Array or Object formed by applying a given function to each element of input.
Type: object
, array
Input Array or Object to process. Function returns array when input is array and object otherwise.
Type: function (value, key)
Function that is called for every element of input iterable. It receives original value
and key
and returns new value that is inserted into output iterable.
Type: function
Optional limit function for concurrency control. See p-limit
.
Single interface for applying regular and async map function to every item of input iterable and returning new iterable with original keys and mapped values.
" It saves my time, Al