- From: Ben Kelly <notifications@github.com>
- Date: Thu, 30 Jul 2015 14:26:03 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Message-ID: <whatwg/streams/issues/383/126495267@github.com>
We need a mechanism like I describe in #384. Imagine something like this:
```
var latch = new TransformStream({
latchedValue: null,
pendingRead: null,
transform: function(chunk, enqueue, done) {
if (this.pendingRead) {
var pr = this.pendingRead;
this.pendingRead = null;
pr(chunk);
return;
}
this.latchedValue = chunk;
},
// this hook doesn't exist yet
pull: function() {
var self = this;
return new Promise(function(resolve, reject) {
if (self.latchedValue) {
var lv = self.latchedValue;
self.latchedValue = null;
resolve(lv);
return;
}
if (self.pendingRead) {
reject('overlapping reads!');
return;
}
self.pendingRead = resolve;
});
}
});
source.pipeThrough(latch).read(); // this triggers pull() function above
```
Although I see what you mean now. The .pipeThrough() will pull values from source that wouldn't have to be produced under normal back pressure mechanisms.
Maybe a wrapped ReadableStream would work. I don't have time to work through the pseudo code right now, unfortunately. It seems that should be possible, though.
---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/383#issuecomment-126495267
Received on Thursday, 30 July 2015 21:26:31 UTC