Re: [ServiceWorker] Can we change the body attribute of Request/Response to a method? (#606)

> I think requiring a stream to be a readable state synchronously at creation time might be a problem. (Or I am confused again!)

Unclear if you are confused :). The stream doesn't necessarily need to be readable synchronously at creation time. But it *does* have to be "on its way" to becoming readable. That is, a very normal usage pattern would be something like

```js
var stream = createStreamOrGetItFromSomewhereLikeReqDotBody();

assert(stream.state === "waiting");
stream.ready.then(() => {
  // The question is, do we ever get here?
  assert(stream.state == "readable");
  console.log(stream.read());
});
```

> Or, does the stream get constructed in the "waiting" state, immediately tries to get the first chunk, and moves to "readable" when its in memory?

Yes, exactly! This came in as I was typing the above :).

> If thats the case, then it seems stream() does not need to be async.

I guess so. The idea being that `.stream()` both returns the stream immediately, and then in the background asynchronously kicks off the IPC stuff necessary to start it filling up?

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/606#issuecomment-70887550

Received on Wednesday, 21 January 2015 17:59:32 UTC