1.7.5-next.06bcc83c • Published 10 months ago

@sapphire/event-iterator v1.7.5-next.06bcc83c

Weekly downloads
11
License
MIT
Repository
github
Last release
10 months ago

Sapphire Logo

@sapphire/event-iterator

Turns event emitter events into async iterators.

GitHub codecov npm bundle size npm Depfu

Table of Contents

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 which can be used with for await...of loops.

Features

  • Written in TypeScript
  • Bundled with Rollup 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.

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

// 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.

API Documentation

For the full API documentation please refer to the TypeDoc generated documentation.

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 WithAddress
Open CollectiveClick Here
Ko-fiClick Here
PatreonClick Here
PayPalClick Here

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

1.7.5-next.1b923add

10 months ago

1.7.4

1 year ago

1.7.5-next.bc2f01ce

10 months ago

1.7.5-next.ab1708e3

12 months ago

1.7.5-next.014a7928

12 months ago

1.7.5-next.7bb00e1e

10 months ago

1.7.5-next.06bcc83c

10 months ago

1.7.5-next.318b047f

12 months ago

1.7.5-next.75165d36

10 months ago

1.7.5-next.51415597

12 months ago

1.7.5-next.1598a42e

10 months ago

1.7.5-next.246fc0d6

12 months ago

1.7.5-next.87bbf48f

10 months ago

1.7.5-next.8a922c42

12 months ago

1.7.5-next.9f0e31f6

11 months ago

1.7.5-next.156b9b1c

12 months ago

1.7.5-next.6f485e71

11 months ago

1.7.5-next.548200f1

12 months ago

1.7.5-next.5d7bdbbc

12 months ago

1.7.5-next.12872de7

10 months ago

1.7.5-next.a6e68f30

10 months ago

1.7.5-next.42db0795

12 months ago

1.7.5-next.a0809c46

11 months ago

1.7.5-next.598c24a3

12 months ago

1.7.5-next.61eebdff

12 months ago

1.7.3

1 year ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago