git ssb

2+

Dominic / pull-stream



Commit 82275cdfd9549c558f2a4d32dc25d931d6672779

better examples

Dominic Tarr committed on 6/22/2016, 11:52:25 PM
Parent: 6dab0f0aee56ec3a23287a6df1a8be33b0bef4ca

Files changed

README.mdchanged
README.mdView
@@ -67,15 +67,14 @@
6767 The `read` function *must not* be called until the previous call has called back.
6868 Unless, it is a call to abort the stream (`read(truthy, cb)`).
6969
7070 ```js
71-//a stream of 100 random numbers.
72-var random = function () {
73- var i = 100
71+//a stream of random numbers.
72+function random (n) {
7473 return function (end, cb) {
7574 if(end) return cb(end)
76- //only read 100 times
77- if(i-- < 0) return cb(true)
75+ //only read n times, then stop.
76+ if(0<--n) return cb(true)
7877 cb(null, Math.random())
7978 }
8079 }
8180
@@ -91,9 +90,9 @@
9190 are reader streams.
9291
9392 ```js
9493 //read source and log it.
95-var logger = function () {
94+function logger () {
9695 return function (read) {
9796 read(null, function next(end, data) {
9897 if(end === true) return
9998 if(end) throw end
@@ -107,9 +106,9 @@
107106
108107 Since these are just functions, you can pass them to each other!
109108
110109 ```js
111-var rand = random()
110+var rand = random(100)
112111 var log = logger()
113112
114113 log(rand) //"pipe" the streams.
115114
@@ -130,9 +129,9 @@
130129 That is, it's just a function that takes a `read` function,
131130 and returns another `read` function.
132131
133132 ```js
134-var map = function (read, map) {
133+function map (read, map) {
135134 //return a readable function!
136135 return function (end, cb) {
137136 read(end, function (end, data) {
138137 cb(end, data != null ? map(data) : null)
@@ -320,4 +319,5 @@
320319 ## License
321320
322321 MIT
323322
323+

Built with git-ssb-web