Skip to content

Commit ad65012

Browse files
committed
initial
0 parents  commit ad65012

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- 0.6
4+
- 0.8

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2016 Dominic Tarr
2+
3+
Permission is hereby granted, free of charge,
4+
to any person obtaining a copy of this software and
5+
associated documentation files (the "Software"), to
6+
deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify,
8+
merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom
10+
the Software is furnished to do so,
11+
subject to the following conditions:
12+
13+
The above copyright notice and this permission notice
14+
shall be included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
20+
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# pull-next
2+
3+
read from one pull-stream, then the next, then the next...
4+
5+
when one stream end (unless it errored) call a function
6+
to get the next stream. much like [pull-cat](https://github.com/pull-stream/pull-cat)
7+
except creates streams by calling a function instead of takeing them out of an array.
8+
9+
in particular, this is useful for making a read stream that reconnects
10+
to a source.
11+
12+
## example
13+
14+
create a stream that reads from a leveldb 100 items at a time.
15+
16+
``` js
17+
var next = require('pull-next')
18+
var pl = require('pull-level')
19+
var db = require('level')(path_to_level)
20+
21+
function resume () {
22+
var last = null
23+
return Next(function () {
24+
return pull(
25+
pl.read(db, {gt: last && last.key, limit: 100}),
26+
pull.through(function (data) { last = data })
27+
)
28+
})
29+
}
30+
31+
```
32+
33+
hint: this might be even more useful over [multilevel](https://github.com/level/multilevel)
34+
35+
## License
36+
37+
MIT
38+
39+
40+
41+
42+

index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var noop = function () {}
2+
3+
module.exports = function (next) {
4+
var stream
5+
return function (abort, cb) {
6+
if(abort) {
7+
if(stream) stream(abort, cb)
8+
else cb(abort)
9+
}
10+
else
11+
more()
12+
13+
function more () {
14+
if(!stream) {
15+
try { stream = next() }
16+
catch(err) { return cb(err) }
17+
if(!stream) return cb(true)
18+
}
19+
stream(null, function (err, data) {
20+
if(err) {
21+
console.log('end', err, data)
22+
stream = null
23+
if(err === true) setTimeout(more, 100)
24+
else cb(err)
25+
}
26+
else
27+
cb(null, data)
28+
})
29+
}
30+
}
31+
}
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "pull-next",
3+
"description": "",
4+
"version": "0.0.0",
5+
"homepage": "https://github.com/dominictarr/pull-next",
6+
"repository": {
7+
"type": "git",
8+
"url": "git://github.com/dominictarr/pull-next.git"
9+
},
10+
"dependencies": {
11+
},
12+
"devDependencies": {
13+
},
14+
"scripts": {
15+
"test": "set -e; for t in test/*.js; do node $t; done"
16+
},
17+
"author": "Dominic Tarr <[email protected]> (http://dominictarr.com)",
18+
"license": "MIT"
19+
}

0 commit comments

Comments
 (0)