Neglected Pizza Money

    @types/event-to-promise
    TypeScript icon, indicating that this package has built-in type declarations

    0.7.2 • Public • Published

    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.

    Keywords

    none

    Install

    npm i @types/event-to-promise

    DownloadsWeekly Downloads

    340

    Version

    0.7.2

    License

    MIT

    Unpacked Size

    7.26 kB

    Total Files

    4

    Last publish

    Collaborators

    • types