Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@metamask/safe-event-emitter

MetaMask2.8mISC3.1.2TypeScript support: included

An EventEmitter that isolates the emitter from errors in handlers

readme

safe-event-emitter

An EventEmitter that isolates the emitter from errors in handlers. If an error is thrown in a handler it is caught and re-thrown inside of a setTimeout so as to not interrupt the emitter's code flow.

The API is the same as a core EventEmitter.

Install

$ yarn add '@metamask/safe-event-emitter'

Usage

import SafeEventEmitter from '@metamask/safe-event-emitter';

const ee = new SafeEventEmitter();
ee.on('boom', () => { throw new Error(); });
ee.emit('boom'); // No error here

// Error is thrown after setTimeout

Release & Publishing

The project follows the same release process as the other libraries in the MetaMask organization:

  1. Create a release branch
    • For a typical release, this would be based on master
    • To update an older maintained major version, base the release branch on the major version branch (e.g. 1.x)
  2. Update the changelog
  3. Update version in package.json file (e.g. yarn version --minor --no-git-tag-version)
  4. Create a pull request targeting the base branch (e.g. master or 1.x)
  5. Code review and QA
  6. Once approved, the PR is squashed & merged
  7. The commit on the base branch is tagged
  8. The tag can be published as needed

Running tests

yarn test

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

3.1.2

Fixed

  • Omit test files from published package (#149)

3.1.1 - 2024-03-12

Fixed

  • Fix ESM module path (#143)
  • Fix ESM source map paths (#146)

3.1.0 - 2024-03-08

Added

  • Add ESM build (#141)

3.0.0 - 2023-04-24

Changed

  • BREAKING: Drop support for Node.js < v12 (#101)

2.0.0 - 2020-09-02

Changed

  • Migrate to TypeScript (#1)