chore: refactor dynamic parameters into dedicated package (#18420)

This PR extracts dynamic parameter rendering logic from
coderd/parameters.go into a new coderd/dynamicparameters package. Partly
for organization and maintainability, but primarily to be reused in
`wsbuilder` to be leveraged as validation.
This commit is contained in:
Steven Masley
2025-06-20 13:00:39 -05:00
committed by GitHub
parent 72f7d70bab
commit 9b5d49967c
10 changed files with 942 additions and 410 deletions

View File

@ -0,0 +1,25 @@
package coderdtest
import "github.com/coder/coder/v2/codersdk/wsjson"
// SynchronousStream returns a function that assumes the stream is synchronous.
// Meaning each request sent assumes exactly one response will be received.
// The function will block until the response is received or an error occurs.
//
// This should not be used in production code, as it does not handle edge cases.
// The second function `pop` can be used to retrieve the next response from the
// stream without sending a new request. This is useful for dynamic parameters
func SynchronousStream[R any, W any](stream *wsjson.Stream[R, W]) (do func(W) (R, error), pop func() R) {
rec := stream.Chan()
return func(req W) (R, error) {
err := stream.Send(req)
if err != nil {
return *new(R), err
}
return <-rec, nil
}, func() R {
return <-rec
}
}