Hacker Newsnew | past | comments | ask | show | jobs | submit | pcattori's commentslogin

Yep, totally could do that. But I like I mentioned here (https://news.ycombinator.com/item?id=34659597) I wanted to keep the interfaces for `compileBrowser` and `compilerServer` since my mental model for it is that those two are "siblings".


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. 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.


> 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.


The main trick on display here is that you can store a reference to the `resolve` method of a promise that normally would have to be called within the promise definition itself.

Of course, you don't need a channel abstraction to do that. To me, channels are the most intuitive and self-contained way to solve the problem, so I wanted to use that model of concurrency in JS.


Its a Typescript-ism for asserting that the value is not `undefined`. So you're telling the typechecker to trust you on this one


Thank you, didn’t know about this one!


That is (was) a good thing! It’s basically the `as any` of strict null checks, and just as unsafe.

Now that you do know about it, please use it sparingly if at all, i.e. when you’re absolutely sure you know more than the type checker, or when you’re in a context where it’ll be caught by other means. My typical lint setup disallows it in source code without an explanatory comment, and allows it in tests under the assumptions that either they’ll fail if wrong or that a reviewer will call out the test as overly complicated.


That's correct. The last three paragraphs of the article cover this and include links to libraries that have "full" channel implementations.


The point about "Inadequate data modelling facilities" is why I wrote Maps: https://github.com/pcattori/maps . Specifically, the "Named Maps" variants provide the same interface as `namedtuple` but for different levels of immutability/mutability.

Feedback/suggestions welcome!


I use the beta version of this library all the time in my code! It was really simple and my code was cleaner, easier to read and write! (link to beta version of library: https://github.com/pcattori/namespaces ). Thanks and I am looking forward to try out Maps now!


This is really cool. NamedDict is a useful thing indeed!


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: