- From: Mattias Buelens <notifications@github.com>
- Date: Sat, 10 Aug 2019 01:37:55 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Saturday, 10 August 2019 08:38:24 UTC
The important bit is that `append()` resolves the promise returned by `waitForData()`. You can't have `waitForData()` loop until `this.source.length` changes, since *nothing else can run* while that loop is going. When you use `new Promise()`, the return value of the callback is ignored. Therefore, `return this.waitForData()` will not "chain" the original promise with the returned promise. (I know, it can be a bit confusing since `.then()` does allow you to return a promise.) One possible solution could be: ```javascript { waitForData() { this.nextDataPromise = new Promise((resolve) => { this.nextDataResolve = resolve; }); if (this.position < this.source.length) { this.nextDataResolve(); } return this.nextDataPromise; } append(newChunks) { this.source.push(...newChunks); if (this.nextDataPromise && this.position < this.source.length) { this.nextDataResolve(); } } } ``` -- 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/streams/issues/1008#issuecomment-520130871
Received on Saturday, 10 August 2019 08:38:24 UTC