Skip to content

feat!: streams as EventTargets #3218

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Jul 11, 2025

  • Converts streams from streaming iterables (e.g. { source, sink }) to EventTargets that have a send method and emit message events.
  • Consolidates:
    • Stream reading/writing/closing into AbstractMessageStream
    • MultiaddrConnection reading/writing/closing into AbstractMultiaddrConnection
    • Stream multiplexing into AbstractStreamMultiplexer

Todo:

  • Compiles
  • Linting
  • Dep-check
  • Tests passing
  • No performance regressions (e.g. perf test-plan should not be slower)

Fixes #3226

BREAKING CHANGE:

  • Streams are now EventTargets, not streaming iterables
  • Stream handlers accept stream, connection, not { stream, connection }

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

We have `MultiaddrConnection`s and `Stream`s, both of which have
`.source` and `.sink` properties, can be aborted or closed gracefully
by iterables ending or explicitly.

All `Stream` implementations extend `AbstractStream` which has let
us concentrate the logic that controls these (many) closing criteria
but the same is not true of `MultiaddrConnection`s.

Where we have these we transform them to async iterables which may not
suit the underlying transport.

Here we consolidate the common parts of `MultiaddrConnection`s into an
`AbstractMultiaddrConnection`, and consolidate the async iterable/closing
parts of both `MultiaddrConnection`s and `Stream`s into a
`HalfCloseableDuplex` abstract superclass.

This greatly simplifies the transport implementations and allows all
transports to benefit from tests run on the super class.
@achingbrain
Copy link
Member Author

Refs: ipshipyard/roadmaps#22

@achingbrain achingbrain changed the title fix: consolidate iterable closing feat!: streams as EventTargets Jul 31, 2025
@achingbrain achingbrain mentioned this pull request Jul 31, 2025
7 tasks
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.

Streams as EventTargets
1 participant