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

listenator

v1.2.3

Published

Turn any event stream into an async iterator

Readme

listenator

TypeScript Dependency Status devDependency Status Build Status Npm Version Deno License Badges

Turn any event stream into an async generator. Inspired by eventChannel from redux-saga. Includes TypeScript typings.

Usage

This package has one default export, listenator, which takes a function as an argument. That function should itself take one or two arguments, emit and optionally done. listenator returns an Asynchronous Generator which yields anything passed to emit. Calling done will flush any queued events and then complete the generator.

Note that this package is not transpiled to ES5. It targets ES2018. If you need to support older browsers or Node versions you will need to process it with Babel or TypeScript.

Examples

Simple

import listenator from 'listenator';

const numbers = listenator((emit, done) => {
  emit(1);
  emit(2);
  emit(3);
  done();
});

// In an async context this will log 1, 2, and then 3:
for await (const num of numbers) {
  console.log(num);
}

// Execution picks up here because `done` was called
console.log('Hello!');

DOM Events

import listenator from 'listenator';

const clicks = listenator((emit) => {
  const button = document.getElementById('my-btn');
  button.addEventListener('click', emit);
});

// In an async context this will log every click event from clicking on #my-btn
for await (const click of clicks) {
  console.log(num);
}

Node Events

import listenator from 'listenator';
import EventEmitter from 'events';

class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();

const events = listenator((emit) => {
  myEmitter.on('event', () => {
    console.log('an event occurred!');
  });
});

myEmitter.emit('event', 'foo');

// In an async context:
for await (const event of events) {
  console.log(event); // Logs 'foo', and then all future emits
}

Multiple Arguments

Just pass an array and destructure it on the way out:

import listenator from 'listenator';

const numbers = listenator((emit) => {
  emit([1, 2, 3]);
});

// In an async context:
for await (const [x, y, z] of numbers) {
  console.log(`(${x}, ${y}, ${z})`);
}

Deno

import listenator from 'https://deno.land/x/listenator/mod.ts';

const numbers = listenator((emit, done) => {
  emit(1);
  emit(2);
  emit(3);
  done();
});

// In an async context this will log 1, 2, and then 3:
for await (const num of numbers) {
  console.log(num);
}

// Execution picks up here because `done` was called
console.log('Hello!');

Contributing

Please run make init in the root directory before making any commits so the commit-msg hook can validate your commit messages.

Prior Art

Other Modules

License

MIT