creationix / continuable

A continuable style interface to node.js
11 stars 0 forks source link

Ideation / overlap / collaboration #1

Open Raynos opened 11 years ago

Raynos commented 11 years ago

I started thinking about the exact same thing API wise.

https://gist.github.com/Raynos/5279565

Not really sure where to go with it. It makes normal callbacks way more composable though

creationix commented 11 years ago

@Raynos DId you see my howtonode article from years ago on this? http://howtonode.org/do-it-fast

I think that I do prefer one callback over two though (in the do article I had two callbacks like in promises). It's closer to node style and makes a lot of the code I've written so far much simpler.

Raynos commented 11 years ago

It's only recently clicked in my head that this style of value and high order programming is amazing. If I had read your article a year ago I would have simply gone "psh yet another flow control library"

I need to think harder about the syntax. Myself & @dominictarr have also done something similar to your stream interface https://github.com/dominictarr/pull-stream and https://gist.github.com/Raynos/5291762

Except it uses Reader(readable) instead of Writable.write(chunk)

Raynos commented 11 years ago

I just updated my module with a map and join function that work over continuables. ( https://github.com/Raynos/continuable#docs ).

This is pretty useful for writing higher order stuff.

creationix commented 11 years ago

Interesting stuff. I explored continuable based streams a lot during my france trip and am really liking how they work out. I especially like my simple interface for protocol translators. In my gamepad example, I open a file using a continuable, create a readable string out of that file descriptor. Use a couple translators to convert the raw file chunks into joystick events and loop over the stream dumping the events.

https://github.com/creationix/moonslice-node/blob/master/testgamepad.js

If you look at the two translators used (https://github.com/creationix/moonslice-node/blob/master/lib/joy.js and https://github.com/creationix/moonslice-node/blob/master/lib/bytesize.js), you'll see that all the complexity of backpressure is handled outside the translater in common code at https://github.com/creationix/moonslice-node/blob/master/lib/streammap.js. Then I can map over streams using Reactive Functional Programming style!

I'm still working out how an HTTP protocol parser would work because of the nested streams, but that should be done soon.