3 ms·
> Generators are JavaScript's programmable semicolons. Lets not take away that power by taking away the programmability. Lets drop async/await and write our own
by kenOfYugen 11y ago
> Generators are JavaScript's programmable semicolons. Lets not take away that power by taking away the programmability. Lets drop async/await and write our own interpreters.
One of "our own interpreters" (i.e not standard in JS), that I am very fond of, is js-csp [1]. It's a replica of Clojure(Script)'s core.async, or Go's channels/goroutines. It uses ES6 generator functions underneath.
James Long has written an excellent post about it [2].
I find it to be the less taxing on the mind solution for coordinating complex asynchronous processes in JS, especially when paired with transducers [3].
Furthermore, powerful Go/Clojure patterns can easily be re-used in JS.
In conjunction with CoffeeScript, the code becomes elegant and straightforward since there is no 'function*' ugliness required.
That's the least complex solution I have found to like the most. Performance and memory usage suffer a bit, but it's very straightforward to optimize if/when needed.
[1] https://github.com/ubolonton/js-csp https://github.com/ubolonton/js-csp
[2] http://jlongster.com/Taming-the-Asynchronous-Beast-with-CSP-in-JavaScript http://jlongster.com/Taming-the-Asynchronous-Beast-with-CSP-...
[3] http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data http://jlongster.com/Transducers.js--A-JavaScript-Library-fo...
- spion 11y agoWhile we're at nicking stuff from Go using generators, our latest effort is adding defer in bluebird :) https://github.com/petkaantonov/bluebird/issues/1014 https://github.com/petkaantonov/bluebird/issues/1014 Its almost done [1], we just want to also support auto-disposable objects so that you don't even need to clean them up with defer. [1]: https://github.com/petkaantonov/bluebird/commit/f944db753ff25e43561fb6c65a6664417b9892cd#diff-3129285757f0c44eca9973432b3bb15aR704 https://github.com/petkaantonov/bluebird/commit/f944db753ff2...
- DonHopkins 11y ago"Programmable semicolons" is a cool sounding term, although I don't quite understand what it really means in relation to JavaScript. Are programmable semicolons optional, and can you program automatically inserted semicolons? It brings to mind my favorite C++ extension: Generalized Overloading for C++2000, that lets you override specific types of white space including space, tab, newline, and even the absence of white space! [1] FORTH has programmable semicolons! : ; POSTPONE EXIT REVEAL POSTPONE [ ; IMMEDIATE There's an interesting comp.lang.forth discussion [2] where somebody asks a great question about defining semicolon in Forth, that's promptly answered by the great Elizabeth D. Rather herself, of FORTH Inc. [3] [4]! [1] http://www.stroustrup.com/whitespace98.pdf http://www.stroustrup.com/whitespace98.pdf [2] https://groups.google.com/forum/#!topic/comp.lang.forth/79XRi5PtK6M https://groups.google.com/forum/#!topic/comp.lang.forth/79XR... [3] https://en.wikipedia.org/wiki/Elizabeth_Rather https://en.wikipedia.org/wiki/Elizabeth_Rather [4] https://archive.org/details/Programm1984 https://archive.org/details/Programm1984