All files of.ts

54.16% Statements 13/24
40% Branches 2/5
62.5% Functions 5/8
54.16% Lines 13/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 443x   12x 12x     1x 1x   1x 1x 9x     9x   9x     1x   1x   1x                                        
import { Channel } from './channel.js'
 
export function of<T>(cap = 0) {
  return new Channel<T>(cap)
}
 
export function ofIterable<T>(iterable: Iterable<T>, cap = 0) {
  const ch = new Channel<T>(cap)
  const produce =
    async () => {
      for (const value of iterable) {
        Iif (ch.doneWriting) {
          break
        }
        await Promise
          .resolve()
          .then(() => ch.write(value))
      }
    }
  produce()
    .finally(() => {
      ch.closeWriting()
    })
  return ch
}
 
export function ofAsyncIterable<T>(asyncIterable: AsyncIterable<T>, cap = 0) {
  const ch = new Channel<T>(cap)
  const produce =
    async () => {
      for await (const value of asyncIterable) {
        Iif (ch.doneWriting) {
          break
        }
        await ch.write(value)
      }
    }
  produce()
    .finally(() => {
      ch.closeWriting()
    })
  return ch
}