‘Taming the Asynchronous Beast with CSP in JavaScript’

James Long:

We already get a hint of how well you can abstract UI code with channels. There are essentially two components: the menu and the tooltip. The menu is a process with its local event loop that waits for something to come from hoverch and creates a tooltip for the target.

The tooltip is its own process that waits 500ms to appear, and if nothing came from the cancel channel it adds the DOM node, waits for a signal from cancel and removes itself. It’s extraordinarily straightforward to code all kinds of interactions.

I really liked this approach to UI. Interestingly, the channel he uses to send a trigger is basically a single-use binary semaphore.