predefined-promise
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.3 • Public • Published

    predefined-promise

    PredefinedPromise is targeting to reference resolve and reject before create Promise instance.

    Usage

    import EventEmitter from "eventemitter3";
    import { PredefinedPromise } from "predefined-promise";
    
    const event = new EventEmitter<{
      resolveEvent: [number];
      rejectEvent: [string];
    }>();
    
    const asyncFunc = (): Promise<number> => {
      const pp = new PredefinedPromise<number>();
      const resolving = (val: number) => pp.resolve(val);
      const rejecting = (reason: string) => pp.reject(new Error(reason));
      event.on("resolveEvent", resolving);
      event.on("rejectEvent", rejecting);
    
      return pp.wait().finally(() => {
        event.off("resolveEvent", resolving);
        event.off("rejectEvent", rejecting);
      });
    };

    Installing

    npm add predefined-promise

    Install

    npm i predefined-promise

    DownloadsWeekly Downloads

    0

    Version

    2.0.3

    License

    ISC

    Unpacked Size

    20.2 kB

    Total Files

    13

    Last publish

    Collaborators

    • sankaku