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])
| 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 |
| 12 | func 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 | } |