Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staltz/callbag-from-pull-stream
👜 Convert a pull-stream to a pullable callbag source
https://github.com/staltz/callbag-from-pull-stream
Last synced: 5 days ago
JSON representation
👜 Convert a pull-stream to a pullable callbag source
- Host: GitHub
- URL: https://github.com/staltz/callbag-from-pull-stream
- Owner: staltz
- License: mit
- Created: 2018-02-16T18:15:56.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-16T18:16:06.000Z (almost 7 years ago)
- Last Synced: 2024-12-19T11:47:23.617Z (25 days ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.js
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - from-pull-stream
README
/**
* callbag-from-pull-stream
* ------------------------
*
* Convert a pull-stream to a pullable callbag source.
*
* `npm install callbag-from-pull-stream`
*
* Example:
*
* const pull = require('pull-stream');
* const {pipe, filter, forEach} = require('callbag-basics');
* const fromPullStream = require('callbag-from-pull-stream');
*
* const source = pull(
* pull.values([1,3,5,7,9]),
* pull.filter(x => x !== 5), // 1,3,7,9
* pull.map(x => x * 10) // 10,30,70,90
* )
*
* pipe(
* fromPullStream(source),
* filter(x => x !== 30), // 10,70,90
* forEach(x => console.log(x))
* )
*/const fromPullStream = read => (start, sink) => {
if (start !== 0) return;
sink(0, (t, d) => {
if (t === 1) read(null, (end, data) => {
if (end === true) sink(2);
else if (end) sink(2, end);
else sink(1, data);
});
if (t === 2) read(d || true, () => {});
});
};module.exports = fromPullStream;