pull-stream
Advanced tools
Comparing version 3.6.1 to 3.6.2
@@ -23,3 +23,3 @@ const bench = require('fastbench') | ||
pull(source, through, sink) | ||
}, | ||
}/*, | ||
function pull_compose (done) { | ||
@@ -50,6 +50,10 @@ const source = pull.values(values) | ||
pull(pull(source, through), sink) | ||
} | ||
], 100000) | ||
}*/ | ||
], N=100000) | ||
run() | ||
var heap = process.memoryUsage().heapUsed | ||
run(function () { | ||
console.log((process.memoryUsage().heapUsed - heap)/N) | ||
}) | ||
@@ -75,2 +75,39 @@ # pull-stream/pull | ||
## Continuable | ||
[Continuables](https://github.com/Raynos/continuable) let you defer a stream and handle the completion of the sink stream. For example: | ||
```js | ||
var cont = pull(...streams, sink) | ||
// ... | ||
cont(function (err) { | ||
// stream finished | ||
}) | ||
``` | ||
Or call beside it if you are not deferring: | ||
```js | ||
pull(...streams, sink)(function (err) { | ||
// stream finished | ||
}) | ||
``` | ||
They are created by making a sink stream return a continuable, which uses it's callback and reads: | ||
```js | ||
function sink (read) { | ||
return function continuable (done) { | ||
// Do reads and eventually call `done` | ||
read(null, function (end, data) { | ||
if (end === true) return done(null) | ||
if (end) return done(end) | ||
// ... otherwise use `data` | ||
}) | ||
} | ||
} | ||
``` | ||
## API | ||
@@ -77,0 +114,0 @@ |
{ | ||
"name": "pull-stream", | ||
"description": "minimal pull stream", | ||
"version": "3.6.1", | ||
"version": "3.6.2", | ||
"homepage": "https://pull-stream.github.io", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -28,5 +28,5 @@ # pull-stream | ||
``` | ||
note that `pull(a, b, c)` is basically the same as `a.pipe(b).pipe(c)`. | ||
Note that `pull(a, b, c)` is basically the same as `a.pipe(b).pipe(c)`. | ||
to grok how pull-streams work, read through [pull-streams by example](https://github.com/dominictarr/pull-stream-examples) | ||
To grok how pull-streams work, read through [pull-streams by example](https://github.com/dominictarr/pull-stream-examples) | ||
@@ -38,3 +38,3 @@ ## How do I do X with pull-streams? | ||
Check the [pull-stream FAQ](https://github.com/pull-stream/pull-stream-faq) | ||
and post an issue if you have a question that is not on that. | ||
and post an issue if you have a question that is not covered. | ||
@@ -60,13 +60,13 @@ ## Compatibily with node streams | ||
### Source (aka, Readable) | ||
### Source (readable stream that produces values) | ||
The readable stream is just a `function read(end, cb)`, | ||
A Source is a function `read(end, cb)`, | ||
that may be called many times, | ||
and will (asynchronously) `cb(null, data)` once for each call. | ||
and will (asynchronously) call `cb(null, data)` once for each call. | ||
To signify an end state, the stream eventually returns `cb(err)` or `cb(true)`. | ||
When indicating a terminal state, `data` *must* be ignored. | ||
When signifying an end state, `data` *must* be ignored. | ||
The `read` function *must not* be called until the previous call has called back. | ||
Unless, it is a call to abort the stream (`read(truthy, cb)`). | ||
Unless, it is a call to abort the stream due to an error (`read(truthy, cb)`). | ||
@@ -86,6 +86,7 @@ ```js | ||
### Sink; (aka, Reader, "writable") | ||
### Sink (reader or writable stream that consumes values) | ||
A sink is just a `reader` function that calls a Source (read function), | ||
until it decideds to stop, or the readable ends. `cb(err || true)` | ||
A Sink is a function `reader(read)` that calls a Source (`read(null, cb`), | ||
until it decides to stop (by calling `read(true, cb)`), or the readable ends (`read` calls | ||
`cb(Error || true)` | ||
@@ -111,3 +112,3 @@ All [Throughs](./docs/throughs/index.md) | ||
Since these are just functions, you can pass them to each other! | ||
Since Sources and Sinks are functions, you can pass them to each other! | ||
@@ -132,6 +133,5 @@ ```js | ||
A through stream is a reader on one end and a readable on the other. | ||
It's Sink that returns a Source. | ||
That is, it's just a function that takes a `read` function, | ||
and returns another `read` function. | ||
A through stream is both a reader (consumes values) and a readable (produces values). | ||
It's a function that takes a `read` function (a Sink), | ||
and returns another `read` function (a Source). | ||
@@ -138,0 +138,0 @@ ```js |
@@ -120,2 +120,46 @@ var pull = require('../') | ||
test('take when abort on the first message', function (t) { | ||
var read = pull( | ||
function (err, cb) { | ||
t.ok(err) | ||
cb(err) | ||
}, | ||
pull.take(5) | ||
) | ||
read(true, function (err) { | ||
t.ok(err) | ||
t.end() | ||
}) | ||
}) | ||
test('take when abort on the first message', function (t) { | ||
var cbs = [] | ||
var read = pull( | ||
function (err, cb) { | ||
cbs.push(cb) | ||
}, | ||
pull.take(5) | ||
) | ||
read(null, function () { | ||
}) | ||
read(true, function (err) { | ||
t.ok(err) | ||
t.end() | ||
}) | ||
t.equal(cbs.length, 2) | ||
var abort_cb = cbs.pop() | ||
abort_cb(true) | ||
}) | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70882
85
1540