-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
commands output unable to stream #453
Comments
The DAG Reader (ipfs cat) is one place where we stream output. That pattern may work here. https://github.com/jbenet/go-ipfs/blob/master/core/commands/cat.go#L37 |
That does work, but would lose the functionality from the encoding system. (You wouldn't be able to get machine-readable output unless you reimplement the handling for the I could modify the commands library to let commands return channels, then the encoding can work like it does now by separately encoding each object received from the channel. (Commands that return channels would do their business logic in a goroutine). Consumers could still get the output as one big array if they want, so this won't break anything. Thoughts? |
returning channels would be a pretty interesting way to retain the machine readability of the output. @jbenet @maybebtc what do you guys think? |
I can't readily visualize how this would work in practice and mix with the rest of the system, so I'm afraid I cannot be of much assistance. |
not channels, use |
channels make more sense for ping though |
not necessarily. it's outputting io to the console. |
mappums argument for the channels was so that we could still retain machine readability using objects and marshallers, we would lose that with a reader/writer |
We actually already support I already did some of the work yesterday making command marshalers return Might be best to punt and do it with an |
Why not http://golang.org/pkg/net/http/#Flusher ?
Agreed, let's not do that.
Yeah... it's probably for the best. what we could do is wrap the type CodecWriter interface {
Write(t interface{}) error
}
type CodecReader interface {
Read(t interface{}) error
}
type jsonWriter struct {...}
func (jw *jsonWriter) Write(t interface{}) error {
enc, err := json.Marshal(t)
if err != nil {
return err
}
for t := 0; t < enc; {
n, err := jw.w.Write(enc)
if err != nil {
return err
}
t = t + n
}
return nil
} |
Actually im sure this exists already. ... and yep:
probably need to wrap these in a common interface (they should all be |
More on
func handle(res http.ResponseWriter, req *http.Request) {
fmt.Fprintf(res, "sending first line of data")
if f, ok := res.(http.Flusher); ok {
f.Flush()
} else {
log.Println("Damn, no flush");
}
sleep(10) //not real code
fmt.Fprintf(res, "sending second line of data")
} |
I think I can mark this closed for now, @mappum implemented channels for streaming output back. |
Related to ipfs#453 but not a fix. This will cause us to actually return early when we start blocking on sending to some peers, but it won't really _unblock_ those peers. For that, we need to write with a context.
It seems to me that all the output for a given command has to be printed at once. Im working on implementing
ipfs ping
and this model doesnt really work, as ping needs to print out a message after each successful (or failed) ping operation. Am I missing a way to do this? or is that not possible?cc @mappum
The text was updated successfully, but these errors were encountered: