WIP jstreamrpc: I don't even know
This commit is contained in:
parent
816a2575a0
commit
dbc9d32193
@ -6,13 +6,13 @@ package jstreamrpc
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/mediocregopher/mediocre-go-lib/jstream"
|
"github.com/mediocregopher/mediocre-go-lib/jstream"
|
||||||
"github.com/mediocregopher/mediocre-go-lib/mrpc"
|
"github.com/mediocregopher/mediocre-go-lib/mrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO Error?
|
// TODO Error?
|
||||||
// TODO SizeHints
|
|
||||||
// TODO it'd be nice if the types here played nice with mrpc.ReflectClient
|
// TODO it'd be nice if the types here played nice with mrpc.ReflectClient
|
||||||
|
|
||||||
type debug struct {
|
type debug struct {
|
||||||
@ -93,10 +93,6 @@ func HandleCall(
|
|||||||
Debug: head.debug.Debug,
|
Debug: head.debug.Debug,
|
||||||
}, rw)
|
}, rw)
|
||||||
|
|
||||||
// TODO unmarshaling request and marshaling response should be in
|
|
||||||
// their own go-routines, just in case they are streams/bytes which depend
|
|
||||||
// on each other
|
|
||||||
|
|
||||||
resErr, resErrOk := rw.Response.(error)
|
resErr, resErrOk := rw.Response.(error)
|
||||||
if resErrOk {
|
if resErrOk {
|
||||||
if err := w.EncodeValue(nil); err != nil {
|
if err := w.EncodeValue(nil); err != nil {
|
||||||
@ -104,13 +100,11 @@ func HandleCall(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := marshalBody(w, rw.Response); err != nil {
|
if err := marshalBody(w, rw.Response); err != nil {
|
||||||
|
if _, ok := err.(net.Error); ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
resErr = err
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the body has been consumed
|
|
||||||
if err := body.Discard(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := w.EncodeValue(resTail{
|
if err := w.EncodeValue(resTail{
|
||||||
@ -120,6 +114,11 @@ func HandleCall(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure the body has been consumed before returning
|
||||||
|
if err := body.Discard(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,13 +151,14 @@ func sqr(r mrpc.Request, rw *mrpc.ResponseWriter) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
rw.Response = func(sw *jstream.StreamWriter) error {
|
rw.Response = func(sw *jstream.StreamWriter) error {
|
||||||
sw = sw.EncodeStream()
|
return sw.EncodeStream(0, func(sw *jstream.StreamWriter) error {
|
||||||
for i := range ch {
|
for i := range ch {
|
||||||
if err := sw.EncodeValue(i * i); err != nil {
|
if err := sw.EncodeValue(i * i); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user