# @sapphire/event-iterator

> Turns event emitter events into async iterators.

Latest version **1.7.4** (published 2024-11-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sapphire/event-iterator
pnpm add @sapphire/event-iterator
yarn add @sapphire/event-iterator
bun add @sapphire/event-iterator
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.7.4 |
| Published | 2024-11-09 |
| First published | 2020-10-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=v14.0.0 |
| Dependencies | 1 |
| Unpacked size | 53.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 191 |
| Author | @sapphire |
| Maintainers | favna, vladfrangu, kyranet |
| Keywords | @sapphire/event-iterator, bot, typescript, ts, yarn, discord, sapphire, standalone |

## Links

- npm: https://www.npmjs.com/package/@sapphire/event-iterator
- Repository: https://github.com/sapphiredev/utilities
- Homepage: https://github.com/sapphiredev/utilities/tree/main/packages/event-iterator
- Issues: https://github.com/sapphiredev/utilities/issues
- npm.io page: https://npm.io/package/@sapphire/event-iterator

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 1.7.4 (latest) — 2024-11-09
- 1.7.5-next.c1299bac (next) — 2026-03-08
- 1.8.0-pr-935.7da5c8bb (pr-935) — 2025-11-25
- 1.7.3-pr-725.55b1ff7b.0 (pr-725) — 2024-03-17
- 1.7.2-pr-684.9d7e2fce.0 (pr-684) — 2023-12-14
- 1.7.0-pr-601.2f2c308a.0 (pr-601) — 2023-05-28
- 1.7.0-pr-589.aa473f9.0 (pr-589) — 2023-05-04
- 1.7.0-pr-587.e9607661.0 (pr-587) — 2023-05-04
- 1.7.0-pr-584.b444d5b.0 (pr-584) — 2023-05-02
- 1.7.0-pr-575.91d23d87.0 (pr-575) — 2023-04-16
- 1.7.0-pr-567.8638d898.0 (pr-567) — 2023-04-06
- 1.7.0-pr-434.77ef153.0 (pr-434) — 2023-01-06
- 1.5.0-pr-270.b2c4518.0 (pr-270) — 2022-01-26
- 1.3.0-pr-160.676f855.0 (pr-160) — 2021-08-23
- 1.3.0-pr-159.fae7a606.0 (pr-159) — 2021-08-23
- … 986 more at https://npm.io/package/@sapphire/event-iterator/versions

## README

<div align="center">

![Sapphire Logo](https://raw.githubusercontent.com/sapphiredev/assets/main/banners/SapphireCommunity.png)

# @sapphire/event-iterator

**Turns event emitter events into async iterators.**

[![GitHub](https://img.shields.io/github/license/sapphiredev/utilities)](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
[![npm bundle size](https://img.shields.io/bundlephobia/min/@sapphire/event-iterator?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@sapphire/event-iterator)
[![npm](https://img.shields.io/npm/v/@sapphire/event-iterator?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@sapphire/event-iterator)

</div>

**Table of Contents**

-   [Description](#description)
-   [Features](#features)
-   [Installation](#installation)
-   [Usage](#usage)
    -   [Basic Usage](#basic-usage)
-   [Buy us some doughnuts](#buy-us-some-doughnuts)
-   [Contributors](#contributors)

## Description

There is often a need to have async iterators with fine control, timeouts, limits, filter, and so on, this package exists to satisfy those needs. By implementing an [async iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) which can be used with [`for await...of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) loops.

## Features

-   Written in TypeScript
-   Bundled with esbuild so it can be used in NodeJS and browsers
-   Offers CommonJS, ESM and UMD bundles
-   Fully tested

## Installation

You can use the following command to install this package, or replace `npm install` with your package manager of choice.

```sh
npm install @sapphire/event-iterator
```

## Usage

**Note:** While this section uses `require`, the imports match 1:1 with ESM imports. For example `const { EventIterator } = require('@sapphire/event-iterator')` equals `import { EventIterator } from '@sapphire/event-iterator'`.

### Basic Usage

```typescript
// Import the EventIterator class
const { EventIterator } = require('@sapphire/event-iterator');

// Define an event iterator with a limit of 2 entries
const iterator = new EventIterator(emitter, 'message', { limit: 2 });

emitter.emit('message', { id: 'foo' });
emitter.emit('message', { id: 'bar' });
emitter.emit('message', { id: 'baz' });

for await (const message of iterator) {
	console.log(message);
	// Logs: { id: 'foo' }
	// Logs: { id: 'bar' }
}

// The iterator ended at second item, { id: 'baz' } is not collected due to the specified limit.
```

---

## Buy us some doughnuts

Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.

|   Donate With   |                       Address                       |
| :-------------: | :-------------------------------------------------: |
| Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
|      Ko-fi      |      [Click Here](https://sapphirejs.dev/kofi)      |
|     Patreon     |    [Click Here](https://sapphirejs.dev/patreon)     |
|     PayPal      |     [Click Here](https://sapphirejs.dev/paypal)     |

## Contributors

Please make sure to read the [Contributing Guide][contributing] before making a pull request.

Thank you to all the people who already contributed to Sapphire!

<a href="https://github.com/sapphiredev/utilities/graphs/contributors">
  <img src="https://contrib.rocks/image?repo=sapphiredev/utilities" />
</a>

[contributing]: https://github.com/sapphiredev/.github/blob/main/.github/CONTRIBUTING.md

---
_Source: https://npm.io/package/@sapphire/event-iterator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
