Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobbubu/pull-pushable-duplex
https://github.com/jacobbubu/pull-pushable-duplex
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jacobbubu/pull-pushable-duplex
- Owner: jacobbubu
- License: mit
- Created: 2020-09-21T05:32:34.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-02T14:58:42.000Z (about 4 years ago)
- Last Synced: 2024-11-07T20:09:29.825Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 94.7 KB
- Stars: 0
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# @jacobbubu/pull-pushable-duplex
[![Build Status](https://github.com/jacobbubu/pull-pushable-duplex/workflows/Build%20and%20Release/badge.svg)](https://github.com/jacobbubu/pull-pushable-duplex/actions?query=workflow%3A%22Build+and+Release%22)
[![Coverage Status](https://coveralls.io/repos/github/jacobbubu/pull-pushable-duplex/badge.svg)](https://coveralls.io/github/jacobbubu/pull-pushable-duplex)
[![npm](https://img.shields.io/npm/v/@jacobbubu/pull-pushable-duplex.svg)](https://www.npmjs.com/package/@jacobbubu/pull-pushable-duplex/)> A helper class for constructing full/half pushable duplex in pull-stream manner.
## Intro.
Constructing a full-duplex, pushable duplex requires complex state management considerations.
Especially, you need to make sure that you follow the guidelines of the pull-stream ([pull-stream-protocol-checker](https://github.com/elavoie/pull-stream-protocol-checker)).
## Usage
``` ts
import * as pull from 'pull-stream'
import { PushableDuplex } from '@jacobbubu/pull-pushable-duplex'function valuesToRead(values: T[] = []) {
let i = 0
return (cb: OnReadCallback) => {
i === values.length ? cb(true) : cb(null, values[i])
i += 1
}
}const results: any[] = []
const d = new PushableDuplex({
allowHalfOpen: true,
onRead: valuesToRead([1, 2, 3]),
onReceived: (data) => {
results.push(data)
},
onFinished: (err) => {
console.log("we've" got, results)
},
})
const peer = {
source: pull.values(['a', 'b', 'c']),
sink: pull.collect((err, results) => {
console.log("peer's got", results)
})
}
pull(d, peer, d)
```