npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bare-channel

v5.2.4

Published

Inter-thread messaging for JavaScript

Readme

bare-channel

Inter-thread messaging for JavaScript. Messages are serialized using the structured clone algorithm provided by https://github.com/holepunchto/bare-structured-clone, allowing arbitrary values and transferable objects to be exchanged between threads.

npm i bare-channel

Usage

const Channel = require('bare-channel')
const { Thread } = Bare

const channel = new Channel()

const thread = new Thread(__filename, { data: channel.handle }, async (handle) => {
  const Channel = require('bare-channel')

  const channel = Channel.from(handle)
  const port = channel.connect()

  for await (const data of port) {
    await port.write(data)
  }
})

const port = channel.connect()

await port.write('ping')

console.log(await port.read())

await port.close()

thread.join()

API

const channel = new Channel([options])

Create a new channel. A channel is a shared rendezvous point between threads; both ends acquire a Port by calling channel.connect() to send and receive messages.

options include:

options = {
  handle,
  interfaces: []
}

handle is an existing SharedArrayBuffer returned by channel.handle on another thread. When provided, the new channel is wired up to the same underlying channel. If omitted, a fresh channel is created.

interfaces is an array of constructors with bare-structured-clone serialize and/or transfer symbols. Instances of these types may be passed to port.write() and will be reconstructed on the receiving side. See https://github.com/holepunchto/bare-structured-clone for the symbols and conventions.

channel.handle

The underlying SharedArrayBuffer for the channel. Pass this across thread boundaries (e.g. via Bare.Thread's data option) and reconstruct the channel on the other side with Channel.from(handle).

channel.interfaces

The array of constructors passed to the constructor.

const port = channel.connect()

Connect a new Port to the channel. A channel supports two connected ports; messages written on one port appear in the read queue of the other.

const channel = Channel.from(handle[, options])

Static helper for constructing a channel from an existing handle. Equivalent to new Channel({ ...options, handle }).

const data = await port.read()

Read the next value from the port. Resolves with null once the remote side has ended and the queue is drained.

const data = port.readSync()

Synchronous variant of port.read() that blocks the current thread until a value is available or the remote side has ended. Returns null when the remote side has ended and the queue is drained.

const flushed = await port.write(value[, options])

Write value to the port. Resolves to true once the value has been accepted into the channel, or false if the remote side has ended.

options include:

options = {
  transfer: []
}

transfer is an array of transferable values that should be transferred to the receiving side rather than cloned, following the structured clone algorithm.

const flushed = port.writeSync(value[, options])

Synchronous variant of port.write() that blocks the current thread when the channel is full until the value can be enqueued. Returns false if the remote side has ended.

const stream = port.createReadStream([options])

Create a Readable stream that consumes values from the port. options are forwarded to https://github.com/holepunchto/bare-stream.

const stream = port.createWriteStream([options])

Create a Writable stream that writes values to the port. The port is closed when the stream is finalized. options are forwarded to https://github.com/holepunchto/bare-stream.

const stream = port.createStream([options])

Create a Duplex stream that both reads from and writes to the port. The port is closed when the stream is finalized. options are forwarded to https://github.com/holepunchto/bare-stream.

await port.close()

Close the port. Pending writes are flushed before the close completes. After the port is closed, further writes resolve to false and reads return null once the queue is drained.

port.ref()

Reference the port, keeping the event loop alive while it is open.

port.unref()

Unreference the port, allowing the event loop to exit even if the port is still open. The port will be closed automatically when no other handles are keeping the event loop alive.

for (const data of port)

Synchronously iterate over values read from the port. Equivalent to repeatedly calling port.readSync() until it returns null.

for await (const data of port)

Asynchronously iterate over values read from the port. Equivalent to repeatedly calling port.read() until it returns null.

event: 'end'

Emitted when the remote side has ended.

event: 'close'

Emitted when the port has been closed.

License

Apache-2.0