[Prototype] Rewrite JSONRPCConnection as an actor with AsyncStream#50
Draft
rintaro wants to merge 1 commit into
Draft
[Prototype] Rewrite JSONRPCConnection as an actor with AsyncStream#50rintaro wants to merge 1 commit into
rintaro wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Experimenting.
Three
AsyncStreams.AsyncStream<OutgoingItem>(outgoingContinuation)Serializes all outgoing work items (notifications, requests, replies) from any caller into the actor. Its
Continuationis aletproperty, makingsend/sendReplyfullynonisolated— callers never have to hop to the actor just to enqueue a message. The fire-and-forget actor task drains it in strict FIFO order, guaranteeing message ordering without a dispatch queue.AsyncStream<Data>(sendContinuation)Decouples the actor-isolated encoding step from the blocking
sendFD.write. The actor encodes a message and yields the bytes synchronously; theTask.detachedsend loop picks them up and blocks the thread waiting on I/O, without ever touching the actor. This is why two "send" streams are needed rather than one: the blocking write must not hold the actor's executor.AsyncStream<Data>(receiveStream, created in_start)Same idea on the read side. The
Task.detachedreader blocks onreceiveFD.read, yields complete framed messages, and the actor-isolatedreceiveLoopTaskpicks them up to decode and dispatch. The stream is the hand-off point between the blocking I/O thread and the actor.