0.7.5 • Published 6 months ago

@types/event-to-promise v0.7.5

Weekly downloads
920
License
MIT
Repository
github
Last release
6 months ago

Installation

npm install --save @types/event-to-promise

Summary

This package contains type definitions for event-to-promise (https://github.com/JsCommunity/event-to-promise).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/event-to-promise.

index.d.ts

// Type definitions for event-to-promise v0.7.0
// Project: https://github.com/JsCommunity/event-to-promise
// Definitions by: flying-sheep <https://github.com/flying-sheep>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node" />

import { EventEmitter } from 'events'

type EventSource = EventEmitter | EventTarget

interface EventToPromiseOptions {
    /**  If true, all parameters of the emitted events are put in an array which is used to resolve/reject the promise. (default: `false`) */
    array?: boolean | undefined,
    /** The name of the event which rejects the promise. (default: `'error'`) */
    error?: string | undefined,
    /** Whether the error event should be ignored and not reject the promise. (default: `false`) */
    ignoreErrors?: boolean | undefined,
}

/**
 * Wait for one event. The first parameter of the emitted event is used to resolve/reject the promise.
 * 
 * @param emitter  The event emitter you want to watch an event on.
 * @param event    The name of the event you want to watch.
 * @param options  An `Object` controlling advanced options.
 * @return         The returned promise has a `cancel()` method which can be used to remove the event listeners. Note that the promise will never settled if canceled.
 */
declare function eventToPromise(emitter: EventSource, event: string, options?: EventToPromiseOptions): Promise<any>;

declare namespace eventToPromise {
    /**
     * Wait for one of multiple events. The array of all the parameters of the emitted event is used to resolve/reject the promise.
     * 
     * The array also has an event property indicating which event has been emitted.
     * 
     * @param emitter        The event emitter you want to watch an event on.
     * @param successEvents  The names of the events which resolve the promise.
     * @param errorEvents    The names of the events which reject the promise. (default: `['error']`)
     * @return               The returned promise has a `cancel()` method which can be used to remove the event listeners. Note that the promise will never settled if canceled.
     */
    export function multi(emitter: EventSource, successEvents: string[], errorEvents?: string[]): Promise<any>;
}

export = eventToPromise

Additional Details

  • Last updated: Thu, 08 Jul 2021 12:01:14 GMT
  • Dependencies: @types/node
  • Global values: none

Credits

These definitions were written by flying-sheep.

0.7.5

6 months ago

0.7.4

7 months ago

0.7.3

8 months ago

0.7.2

3 years ago

0.7.1

4 years ago

0.7.0

8 years ago