3 ms·
All these problems are solvable (streams by ditching built-in streams and replacing them with something decent, errors with promises + typescript, event loop bl
by spion 12y ago
All these problems are solvable (streams by ditching built-in streams and replacing them with something decent, errors with promises + typescript, event loop blocking with a streaming JSON parser). But that still means that out of the box node is a pretty unsatisfying experience all around.
It took us a year to arrive at the solutions above, and many prominent members of the community scoffed at a number of them. Some are still scoffed at.
For example, everyone still thinks that promises should not catch errors, as if somehow throwing on typos is useful. Its not. The real solution here is a type system, the sensible error capturing model of promises that doesn't destroy all assumptions about code (unlike domains), and a sensible library like bluebird that reports rather than swallows up unhandled errors.
People also swore that streams are the best thing ever but the reality is that the built in streams are an organically grown design that accreted many flaws along the way. Most of them can be mended though and with streams 3 things are finally starting to be acceptable.
- astrodust 12y agoAfter using Q for some time and recently discovering Bluebird, I've got to say Bluebird is the way it should have been done. Great library and the API offers a lot of conveniences without being overwhelming.
- xhrpost 12y ago> "ditching built-in streams and replacing them with something decent" What have you found sufficient for this?
- glibgil 12y agoThey just told you: Bluebird and streams 3. Did you get bored and stop reading?
- juliangregorian 12y agoOoh, swing and a miss. Bluebird is not a streams replacement, streams 3 IS the built-in streams. Maybe save the snark for situations where you actually have a clue.
- glibgil 12y agoBluebird is for promises. Mentioned above if you read.
- spion 12y agoWe have an inhouse solution which is basically a set of external functions that work with built in streams in a way that avoids frustration. Some of them can be found in https://github.com/spion/promise-streams https://github.com/spion/promise-streams - the others we haven't extracted to an npm module yet. (Promise streams also has a minimal extension of built in streams to make them work better with promises). We never managed to find a full replacement though. Probably not worth the effort either given that it will always have to wrap existing streams, and the only drawback of external functions is that you cannot invoke them as methods. Although, one contender that I have hopes for is WHATWG streams [1]. note: to replace event emitters we built https://github.com/doxout/promise-observer https://github.com/doxout/promise-observer which gives you a lot more power and control in terms of execution order and goes away with the "multiple events per object" stringy design that makes things harder for typesystems like typescript/flow. [1]: https://github.com/whatwg/streams https://github.com/whatwg/streams
- philbo 12y ago> event loop blocking with a streaming JSON parser Apologies for taking this opportunity to shamelessly plug my streaming JSON parser, which I recently open-sourced here: https://github.com/philbooth/bfj https://github.com/philbooth/bfj