WIP jstreamrpc: messing around with example
This commit is contained in:
parent
196e119c30
commit
e5fbacbd30
@ -124,41 +124,26 @@ func HandleCall(
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
func sqr(r mrpc.Request, rw *mrpc.ResponseWriter) {
|
func sqr(r mrpc.Request, rw *mrpc.ResponseWriter) {
|
||||||
var el jstream.Element
|
var inCh chan jstream.Element
|
||||||
if err := r.Unmarshal(&el); err != nil {
|
if err := r.Unmarshal(&inCh); err != nil {
|
||||||
rw.Response = err
|
rw.Response = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sr, err := el.DecodeStream()
|
outCh := make(chan int)
|
||||||
if err != nil {
|
|
||||||
rw.Response = err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ch := make(chan int)
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(ch)
|
defer close(outCh)
|
||||||
for {
|
for el := range inCh {
|
||||||
var i int
|
var i int
|
||||||
if err := sr.Next().Value(&i); err == jstream.ErrStreamEnded {
|
// TODO this is the problem right here. Getting this error out of
|
||||||
return
|
// here so that the response stream can be canceled
|
||||||
} else if err != nil {
|
if err := el.DecodeValue(&i); err != nil {
|
||||||
panic("TODO")
|
panic(err)
|
||||||
}
|
}
|
||||||
ch <- i
|
outCh <- i*i
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
rw.Response = func(sw *jstream.StreamWriter) error {
|
rw.Response = outCh
|
||||||
return sw.EncodeStream(0, func(sw *jstream.StreamWriter) error {
|
|
||||||
for i := range ch {
|
|
||||||
if err := sw.EncodeValue(i * i); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -51,7 +51,7 @@ type ResponseWriter struct {
|
|||||||
type Response struct {
|
type Response struct {
|
||||||
// Unmarshal takes in a pointer value into which the Client will unmarshal
|
// Unmarshal takes in a pointer value into which the Client will unmarshal
|
||||||
// the response value. The exact nature and behavior of how the pointer
|
// the response value. The exact nature and behavior of how the pointer
|
||||||
// value is treated is dependend on the RPC implementation.
|
// value is treated is dependent on the RPC implementation.
|
||||||
Unmarshal func(interface{}) error
|
Unmarshal func(interface{}) error
|
||||||
|
|
||||||
// Debug will be whatever debug information was set by the server when
|
// Debug will be whatever debug information was set by the server when
|
||||||
|
Loading…
Reference in New Issue
Block a user