From dbc9d321938e4e7561d9c2e3d740ba278ee52d66 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 17 May 2018 10:50:39 +0000 Subject: [PATCH] WIP jstreamrpc: I don't even know --- mrpc/jstreamrpc/jstreamrpc.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mrpc/jstreamrpc/jstreamrpc.go b/mrpc/jstreamrpc/jstreamrpc.go index 5b07c7c..6200e47 100644 --- a/mrpc/jstreamrpc/jstreamrpc.go +++ b/mrpc/jstreamrpc/jstreamrpc.go @@ -6,13 +6,13 @@ package jstreamrpc import ( "context" "errors" + "net" "github.com/mediocregopher/mediocre-go-lib/jstream" "github.com/mediocregopher/mediocre-go-lib/mrpc" ) // TODO Error? -// TODO SizeHints // TODO it'd be nice if the types here played nice with mrpc.ReflectClient type debug struct { @@ -93,10 +93,6 @@ func HandleCall( Debug: head.debug.Debug, }, 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) if resErrOk { if err := w.EncodeValue(nil); err != nil { @@ -104,15 +100,13 @@ func HandleCall( } } else { if err := marshalBody(w, rw.Response); err != nil { - return err + if _, ok := err.(net.Error); ok { + return err + } + resErr = err } } - // make sure the body has been consumed - if err := body.Discard(); err != nil { - return err - } - if err := w.EncodeValue(resTail{ debug: debug{Debug: rw.Debug}, Error: resErr, @@ -120,6 +114,11 @@ func HandleCall( return err } + // make sure the body has been consumed before returning + if err := body.Discard(); err != nil { + return err + } + return nil } @@ -152,13 +151,14 @@ func sqr(r mrpc.Request, rw *mrpc.ResponseWriter) { }() rw.Response = func(sw *jstream.StreamWriter) error { - sw = sw.EncodeStream() - for i := range ch { - if err := sw.EncodeValue(i * i); err != nil { - return err + 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 + return nil + }) } } */