Re:Go-like channels in 10 lines of JavaScript
by 9dev on Saturday February 04, 2023 @06:35PM
(#34659632)
Even better, make use of the built-in promise helpers:
const manifest = await createAssetsManifest();
await Promise.all([
compileBrowser(manifest),
compileServer(manifest)
]);
That makes for such nice, clear code!
Re:Go-like channels in 10 lines of JavaScript
by pcattori on Saturday February 04, 2023 @06:31PM
(#34659597)
The manifest is an artifact produced by the browser compilation, but it can be shared _before_ the browser compilation writes its results to disk.
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. So prefer to use channels instead.
Re:Go-like channels in 10 lines of JavaScript
by taveras on Saturday February 04, 2023 @07:21PM
(#34660076)
> but that's not how I model it in my head.
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.
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?