-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
better documentation for learners #2
Comments
I'd put networking and fs in here too, perhaps also JSON parsing - covering a good rang of practical uses makes it more likely people will use it. |
ooh yes, this is awesome! really keen on more accessible documentation for pull streams. 🐱 other ideas:
also, some examples of other nice "stream" documentation in the wild: /cc @pietgeursen |
I think the most important thing here is to find realistic examples that represent problems that are interesting and or people actually have. Oh, another category is real time data, and streaming of that. maybe an example is an infinite scroller that uses back pressure to stop reading while until you scroll down more. |
@ahdinosaur compose https://github.com/dominictarr/pull-stream-examples/blob/master/compose.js |
@dominictarr maybe I misunderstood this because I'm still trying to learn this concept, but running the last example in function take(n) {
return function(read) {
return function(abort, cb) {
if (!n--) return read(true, cb);
read(null, cb);
};
};
} |
@eugene-eeo good point. fixed |
Another cool pattern I found myself needing the other day was: Eventual valuesReturn a stream from a function synchronously, emit data from it const notify = require('pull-notify')
const pull = require('pull-stream')
const xhr = require('xhr')
pull(request('foobar.com'), pull.log())
function request (url) {
const xhr$ = notify()
xhr(url, (err, res, body) {
if (err) return xhr$.abort(err)
xhr$(body)
xhr$.end()
})
return xhr$.listen()
} Probably not doing it 100% right here - while this could be expanded to be a |
hey @yoshuawuyts, i wrote
function request (url) {
return pullAsync(cb => {
xhr(url, (err, res, body) => {
if (err) return cb(err)
cb(body)
})
})
}
function request (url) {
var deferred = pullDefer.source()
xhr(url, (err, res, body) => {
if (err) deferred.abort(err)
else deferred.resolve(pull.values([body]))
})
return deferred
} |
@yoshuawuyts that way ruins back pressure (not that it matters with XHR, though) |
we need lots more examples to make pull streams easy to learn.
@yoshuawuyts @ahdinosaur @DamonOehlman @pfraze any other ideas?
The text was updated successfully, but these errors were encountered: