Skip to content

Simplify threading aspects of outgoing PipeWriter #5

@kzu

Description

@kzu

We currently use a different Pipe for the outgoing bytes, which means we need to account for two threads active simultaneously, one for reading and one for writing (since we write to its Output and then need another loop for reading from the output pipe for ultimate sending via the websocket.

This introduces subtle and non-obvious dependencies between read/write, which are hard to document and easy to trip over. A much better approach would be to expose a PipeWriter that simply interfaces directly with the underlying websocket, so that writing to it causes an immediate SendAsync over the websocket of a fully completed message (that is, with EndOfMessage=true). This seems like the most common and useful path, and avoids multiple issues that are otherwise quite non-trivial to resolve.

This means the RunAsync is basically independent of writing to the output too, since the former only deals with the input/incoming side of the websocket exclusively. It's up to the user to spin up a separate thread for that purpose or not, at that point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions