MCPcopy Index your code
hub / github.com/coder/coder / SynchronousStream

Function SynchronousStream

coderd/coderdtest/stream.go:12–25  ·  view source on GitHub ↗

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 cas

(stream *wsjson.Stream[R, W])

Source from the content-addressed store, hash-verified

10// The second function `pop` can be used to retrieve the next response from the
11// stream without sending a new request. This is useful for dynamic parameters
12func SynchronousStream[R any, W any](stream *wsjson.Stream[R, W]) (do func(W) (R, error), pop func() R) {
13 rec := stream.Chan()
14
15 return func(req W) (R, error) {
16 err := stream.Send(req)
17 if err != nil {
18 return *new(R), err
19 }
20
21 return <-rec, nil
22 }, func() R {
23 return <-rec
24 }
25}

Callers 2

Calls 2

SendMethod · 0.65
ChanMethod · 0.45

Tested by 2