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
Structured cloning of streams (response/request/fetch) #313
Comments
Tried to assign this to @domenic but that did not work. |
Need to think about: fetch(request).then(function(response) {
response.body.to('json').then(function(data) {
if (!data.err) {
myCache.put(request, response);
}
});
}); …too. Would that fail because the stream was already depleted? |
Yes that would fail. That is why @domenic suggested |
I don't think that would make it more apparant. Happy with Hah, you beat me to the |
@sicking's breakdown of the three use cases in domenic/cloning-and-transfering#1 (comment) speaks to me. For example, when cloning to disk (e.g. adding to cache), the most useful behavior seems to me to be to tee the stream, then read it to the end, and only after the read is completely done (could be never), serialize it to the disk as a snapshot of the contents. Whereas, when cloning (transfering?) to a worker, you don't really want to disturb the state, or wait for it. You just want the worker to have access to it and the ability to grab any data that comes out of it. The essential problem, with both streams and promises, is that someone else is controlling the "actual data" of the object, and doing so asynchronously. They're not just static objects that you can snapshot; they are intimately tied to asynchronous processes initiated and controlled by their creator, that may still be ongoing. |
It seems on memory constrained platforms, like mobile, we would probably want to be able to stream straight to disk. This could be to a temporary file, however, and then only moved to its final storage location when complete. Also, if code calls Perhaps thats a cache detail, but seems related to how we clone the response stream. |
My thought was that the |
Ok. So the secondary, late |
See dslomov/ecmascript-structured-clone#5 and dslomov/ecmascript-structured-clone#6 for the latest on this. |
In issue #361 there's some interesting discussion of how a late commit to cache.add() can lead to service workers issuing duplicate requests that erase each other in the cache. |
This issue appears to be a spec issue with no implementation impact on MVP beyond what's being called out in 361/362. Defining storage in terms of structured-clone simplifies specs and adds new functionality like sending Request/Response objects via postMessage or storing in IDB. |
Let's close this. For this we need structured cloning of promises/streams. One we have that I'm sure we'll have another look at this and other objects representing streams. |
w3c/ServiceWorker#313 was closed long ago and it hasn’t really come up since.
When you put a response or request in storage, it needs to be structured clone. However, we don't want the stream to be depleted in that case so
remains working. It seems we need to figure out what we want out of domenic/cloning-and-transfering#1 before we can implement and ship this.
The text was updated successfully, but these errors were encountered: