Skip to content
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

Merged
merged 3 commits into from
Oct 21, 2019

Conversation

jacobheun
Copy link
Contributor

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.

docs: add iterable types from @alanshaw's gist
doc/STREAMING_ITERABLES.md Outdated Show resolved Hide resolved
Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio>

// Wrapper is what we will write and read from
// This gives us two duplex iterables that are internally connected
const wrapper = duplexPair()
Copy link
Member

@alanshaw alanshaw Oct 21, 2019

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:

Suggested change
const wrapper = duplexPair()
const [client, server] = duplexPair()

Copy link
Contributor Author

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.

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())
Copy link
Member

@alanshaw alanshaw Oct 21, 2019

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

Suggested change
console.log('Data: %s', chunk.slice())
console.log('Data: %s', chunk.toString())

- [Iterable Modules](#iterable-modules)

## Usage Guide

**Coming Soon!**
### Wrapping Duplex Iterables
Copy link
Member

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.

@jacobheun jacobheun merged commit 6ecc9b8 into refactor/async-await Oct 21, 2019
@jacobheun jacobheun deleted the docs/iterable-streams branch October 21, 2019 11:36
dirkmc pushed a commit that referenced this pull request Nov 26, 2019
* 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
dirkmc pushed a commit that referenced this pull request Nov 26, 2019
* 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
jacobheun added a commit that referenced this pull request Dec 12, 2019
* 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
jacobheun added a commit that referenced this pull request Jan 24, 2020
* 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
maschad pushed a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
)

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>
maschad pushed a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
## [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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants