[whatwg/fetch] Fetch Streaming Intermediate Emissions (#349)

I'm consuming a JSON stream and am trying to use fetch to consume it. The stream emits some data every few seconds. Using fetch to consume the stream gives me access to the data only when the stream closes server side. For example:

```JS
var target; // the url.
var options = {
  method: "POST",
  body: bodyString,
} 
var drain = function(response) { 
  // response.body is always undefined. Can't use the reader it provides.
  return response.text(); // or response.json();
};
var listenStream = fetch(target, options).then(drain).then(console.log).catch(console.log);

/*
    returns a data to the console log with a 200 code only when the server stream has been killed.
*/
```

However, there have been several chunks of data already sent to the client. 

Using a node inspired method in the *browser* like this works every single time an event is sent:

```JS
var request = require('request');
var JSONStream = require('JSONStream');
var es = require('event-stream');

request(options)
.pipe(JSONStream.parse('*'))
.pipe(es.map(function(message) { // Pipe catches each fully formed message.
      console.log(message)
 }));
```

What am I missing? My instinct tells me that fetch should be able to mimic the ```pipe```  or stream functionality.

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/349

Received on Wednesday, 3 August 2016 04:23:38 UTC