developit / asyncro Goto Github PK
View Code? Open in Web Editor NEW⛵️ Beautiful Array utilities for ESnext async/await ~
Home Page: https://developit.github.io/asyncro
⛵️ Beautiful Array utilities for ESnext async/await ~
Home Page: https://developit.github.io/asyncro
See #3
And change https://github.com/developit/asyncro/blob/master/src/util.js#L6 to be
acc.push(await v());, but I'm not sure if that's the best way.
** This would break the parallel method, so no go there
Hi @developit. I had a quick look on your lib, but something seemed rather strange to me.
Why does map()
run the callback serially? The nice thing about map
is that it provides great opportunities for concurrent processing.
Let's say I do map(['/a', '/b', '/c'], async (item) => await fetch(item))
and every fetch takes 100ms. I would expect the map()
to resolve after 100ms, not 300 ms.
Doing filter()
and reduce()
concurrently might get tricky, but map()
should be rather carefree :)
Cheers
Awesome, asyncro
is both simple and practical.
Some suggestions:
Array
operators. In fact, most operators are the same pattern like filter
.Object
, maybe like lodash.js
.If you have any plan, very happy to make a PR. 🐵
From what I can tell, the series
method is actually executing all of the methods when it's called, and then waiting for each one to resolve in series before adding it to the array. I think the expected behavior would be that each method is not called until the previous one has resolved.
series([1,2,3,4].map((n) => {
return async () => new Promise((resolve) => {
console.log(n)
setTimeout(() => resolve(n), 1000)
})
}))
Expected: Each number is logged out 1 second after the previous, total runtime is ~4 seconds
Actual: All numbers are printed immediately, total runtime is ~1 second
I think one way of solving this would be to remove https://github.com/developit/asyncro/blob/master/src/util.js#L6
And change https://github.com/developit/asyncro/blob/master/src/util.js#L6 to be
acc.push(await v());
, but I'm not sure if that's the best way.
** This would break the parallel
method, so no go there
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.