Allow Dispatcher to inject a custom generator_class#21
Open
andriytyurnikov wants to merge 1 commit intostarfederation:mainfrom
Open
Allow Dispatcher to inject a custom generator_class#21andriytyurnikov wants to merge 1 commit intostarfederation:mainfrom
andriytyurnikov wants to merge 1 commit intostarfederation:mainfrom
Conversation
Adds an optional generator_class: keyword to Dispatcher.new (defaulting to ServerSentEventGenerator) and routes the three internal generator instantiations — stream_one, stream_many's connection generator, and each per-stream generator inside spawned threads — through it. Lets downstream wrappers layer behavior (logging, metrics, input scrubbing, etc.) on top of the SDK by passing a subclass, instead of monkey-patching the SDK class.
Author
|
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.
Summary
Adds an optional
generator_class:keyword toDatastar::Dispatcher#initialize(defaulting toServerSentEventGenerator). The three internal generator instantiations —stream_one,stream_many's connection generator, and each per-stream generator inside spawned threads — now go through the injected class.Why
Downstream wrappers around Datastar (e.g.
vibes-datastar) need to layer behavior on top of the SSE generator: input scrubbing, logging, metrics, debug capture, etc. Today the only option is monkey-patchingServerSentEventGenerator, because the dispatcher hard-codes the class at three call sites — and the user code insideDispatcher#stream { |sse| ... }always receives an SDK-instantiated generator. Letting the dispatcher accept a subclass is the standard "let the wrapper override the workhorse class" hook.This is the smaller, orthogonal change discussed in the comment thread on #18.
API
Tests
4 new specs under `Dispatcher :generator_class`:
Full suite: 104 examples, 0 failures.
Notes
Test plan