Comment

Comment by lexicality

Not that it matters because you don't care and no one uses promises any more but it does really sadden me how much nested promise code I've found over the years.

eg this

    function sad(input) {
        return new Promise((resolve, reject) =>
            foo(input).then((data) => {
                bar(data).then((data2) => {
                    baz(data2).then(resolve, reject)
                })
            })
        );
    }
could quite as easily have been written like this:

    function happy(input) {
        return foo(input)
            .then((data) => bar(data))
            .then((data2) => baz(data2))
    }
But no one seemed to be aware that you can return a promise in the `.then()` callback and have it chain neatly...
parent lexicality 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton