Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ in pull-streams i like to call streams that data comes out of "sources",
(in node they are usually called readables)

*/
function values (ary) {
var i = 0
return function read(abort, cb) {
if(i===ary.length || abort) return cb(true)
cb(null, ary[i++])
}
}

const values = array => (abort, cb) => array.length
? cb(null, array.shift())
: cb(true)

const c = console.log
, stream = values([1,2,3])

c("Pulling data from the stream...")
stream(null, c)
stream(null, c)
stream(null, c)
stream(null, c)

/*

Expand Down Expand Up @@ -152,7 +158,8 @@ now we can pipe the infinite stream through this,
and it will stop after 101 items!
*/

pull(infinite(), mapper, take(101), sink)
c("Pulling from the infinite stream...")
pull(infinite(), mapper, take(10), sink)

/*
That covers 3 types of pull streams. Source, Transform, & Sink.
Expand Down