-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add stream wrapping example #466
Conversation
docs: add iterable types from @alanshaw's gist
Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio>
doc/STREAMING_ITERABLES.md
Outdated
|
||
// Wrapper is what we will write and read from | ||
// This gives us two duplex iterables that are internally connected | ||
const wrapper = duplexPair() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to name these pairs to make it easier to understand in the example.
For example:
const wrapper = duplexPair() | |
const [client, server] = duplexPair() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with internal
and external
. I don't feel great about these names, but the pairing is used to have 1 half integrate with the external duplex connection and the other half is what we would use internally to read/write data to.
doc/STREAMING_ITERABLES.md
Outdated
async (source) => { | ||
for await (const chunk of source) { | ||
// Chunk will be a BufferList, we can slice it to get the underlying buffer | ||
console.log('Data: %s', chunk.slice()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just call toString()
. In the example there's nothing to say what existingDuplex
is yielding so personally I wouldn't complicate it (then you can remove the comment).
https://github.com/rvagg/bl#toString
console.log('Data: %s', chunk.slice()) | |
console.log('Data: %s', chunk.toString()) |
doc/STREAMING_ITERABLES.md
Outdated
- [Iterable Modules](#iterable-modules) | ||
|
||
## Usage Guide | ||
|
||
**Coming Soon!** | ||
### Wrapping Duplex Iterables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd express this in terms of what it enables you to do. Typically people know what they want to do but don't know how to do it.
* docs: add duplex wrapping example docs: add iterable types from @alanshaw's gist * docs(fix): add feedback fix Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio> * docs: clean up based on feedback
* docs: add duplex wrapping example docs: add iterable types from @alanshaw's gist * docs(fix): add feedback fix Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio> * docs: clean up based on feedback
* docs: add duplex wrapping example docs: add iterable types from @alanshaw's gist * docs(fix): add feedback fix Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio> * docs: clean up based on feedback
* docs: add duplex wrapping example docs: add iterable types from @alanshaw's gist * docs(fix): add feedback fix Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio> * docs: clean up based on feedback
) Bumps [@libp2p/interface-libp2p](https://github.com/libp2p/js-libp2p-interfaces) from 2.0.0 to 3.0.0. - [Release notes](https://github.com/libp2p/js-libp2p-interfaces/releases) - [Commits](https://github.com/libp2p/js-libp2p-interfaces/compare/@libp2p/interface-libp2p-v2.0.0...@libp2p/interface-libp2p-v3.0.0) --- updated-dependencies: - dependency-name: "@libp2p/interface-libp2p" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alex Potsides <alex@achingbrain.net>
## [9.1.3](libp2p/js-libp2p-kad-dht@v9.1.2...v9.1.3) (2023-05-04) ### Dependencies * **dev:** bump @libp2p/interface-libp2p from 2.0.0 to 3.0.0 ([libp2p#466](libp2p/js-libp2p-kad-dht#466)) ([d8f8e5a](libp2p/js-libp2p-kad-dht@d8f8e5a))
docs: add iterable types from alanshaw's gist
This adds a new, and the first, example for streaming iterables. I was working on the crypto interface and needed to do this, so sharing it here.
I also pulled over snippets of the iterables types from @alanshaw's gist to avoid being reliant on that always existing, but I made sure to link to it to credit his work.