alanshaw / alanshaw/it-pushable
Simplify?
- Ngôn ngữ chính
- TypeScript
- Star
- 15
- Fork
- 7
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I combined with `p-fifo` to come up with something way simpler, which gives us nearly all of the functionality we have here and allows an `await pushable.push(value)` - so you can know when the pushed value has been consumed or `await pushable.end()` - so you know when the stream has been drained and ended.
```js
const FIFO = require('p-fifo')
const defer = require('p-defer')
module.exports = function Pushable () {
const errorPromise = defer()
const returnPromise = defer()
const fifo = new FIFO()
return {
[Symbol.asyncIterator] () {
return this
},
next: () => Promise.race([
errorPromise.promise,
returnPromise.promise,
fifo.shift()
]),
return: async () => {
returnPromise.resolve({ done: true })
return { done: true }
},
throw: async err => {
errorPromise.reject(err)
return { done: true }
},
push: value => fifo.push({ value }),
end: async err => {
if (err) {
errorPromise.reject(err)
return
}
return fifo.push({ done: true })
}
}
}
```
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.