- From: Ben Kelly <notifications@github.com>
- Date: Fri, 21 Jul 2017 08:31:13 -0700
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Friday, 21 July 2017 15:31:34 UTC
Here is some pseudo code of what I am talking about in https://github.com/w3c/ServiceWorker/issues/1168#issuecomment-317031289. This is from our gecko bug where I'm trying to explain how we can pump the ReadableStream into our native pipe buffering stream. Its a two stage loops to handle blocking on either ReadableStream or the buffer being full.
```
1) The "outer" loop is doing:
function outer() {
// read next chunk
return stream.reader().read().then(chunk => {
// wait until we have pushed it into the pipe
return inner(chunk);
})
// repeat
.then(outer);
}
2) The "inner" loop is doing:
function inner(chunk) {
return new Promise(resolve => {
let remaining = chunk.length;
let offset = 0;
function writeSegment() {
let written = pipeWriter.write(chunk + offset, remaining);
remaining -= written;
offset += written;
// done
if(remaining < 1) {
resolve();
return;
}
// wait for more room, then loop
pipeWriter.asyncWait(writeSegment);
}
});
};
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1168#issuecomment-317032758
Received on Friday, 21 July 2017 15:31:34 UTC