by bebrws · 3y ago · 0 comments
const manifest = await createAssetsManifest();
compileBrowser(manifest);
compileServer(manifest);
I am wondering if since the creation of async/await that the idea behind callbacks and async operations in general in Node has been forgotten.Not referring to the author or anyone in particular. Just a thought since these keywords might used so often by engineers new to Node that they might not have ever learned what came before?
const manifest = await createAssetsManifest();
await Promise.all([
compileBrowser(manifest),
compileServer(manifest)
]);
That makes for such nice, clear code!I _could_ refactor to have "browser compilation phase 1", then assets manifest, and then "browser compilation phase 2", but that's not how I model it in my head. Plus it would mean a diverging interface for `compileBrowser` and `compileServer` which doesn't fit my mental model either.
So prefer to use channels instead.
I think this is the central matter when it comes to primitives for asynchronous programming.
There exist many ways we can think about async tasks. The JavaScript ecosystem provides for multiple. i.e., event callbacks, async/await, generators, and more.
Programmer reach for tools which best match how we have learned to model these problems in our heads.
It's okay for people to use what works best for them.