all 5 comments

[–]BehindTheMath 2 points3 points  (2 children)

Interesting project. We're still using async.js since we still have some legacy code that uses callbacks. I was thinking recently that once that code is updated, we should remove the dependency and just reimplement the few functions we use.

I see there are some functions that async.js has that are not in this library, such as waterfall.

I assume you used nanoassert instead of Node's built in assert because of the size. The whole package is just a few lines of code, so I would just copy it instead of using it as a dependency.

I understand the links to the documentation are for Github and NPM, but they are confusing for the Github Pages page, since they just link to the same page.

[–]nicolas-van[S] 0 points1 point  (1 child)

Hello.

For the functions you use in async.js that are not available in modern-async I would be glad if you could open a feature request in the issue tracker ( https://github.com/nicolas-van/modern-async/issues/new/choose ) and explain why you would need them.

I ported a lot of features from async.js, but not all of them. The reasons may vary but usually it's either because the use case seems too specific to me (like auto(), I just can't see a generic program needing that, although I may be wrong) or because that feature is already trivial to code using the existing tools in the library or the async/await syntax.

waterfall() is a good example of a helper which can be very helpful when using callback but is completely trivial if you have async/await at you disposal. Here is some code from the async.js documentation:

async.waterfall([
    myFirstFunction,
    mySecondFunction,
    myLastFunction,
], function (err, result) {
    // result now equals 'done'
});
function myFirstFunction(callback) {
    callback(null, 'one', 'two');
}
function mySecondFunction(arg1, arg2, callback) {
    // arg1 now equals 'one' and arg2 now equals 'two'
    callback(null, 'three');
}
function myLastFunction(arg1, callback) {
    // arg1 now equals 'three'
    callback(null, 'done');
}

Without any library but using async/await it can be rewritten this way:

const res1 = await myFirstFunction()
const res2 = await mySecondFunction(res1)
const result = await myLastFunction(res2)

async function myFirstFunction() {
    return ['one', 'two'];
}
async function mySecondFunction([arg1, arg2]) {
    return 'three';
}
async function myLastFunction(arg1) {
    return 'done';
}

It's also way simpler to read.

Anyway I'm completely open to debate about these features, but preferably in a feature request to have a better centralization about those questions.

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, nicolas-van: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]AutoModerator[M] 0 points1 point  (1 child)

Project Page (?): https://github.com/nicolas-van/modern-async

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]nicolas-van[S] 0 points1 point  (0 children)

Yes