0.1.2 • Published 3 years ago

kaphein-js-signal v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

kaphein-js-signal

A waitable object for Javascript based on ECMAScript 6 Promise.

Requirements

Your environment must support ECMAScript 6 Promise class. If not available, it must be shimmed with a third-party implementation such as bulebird.

const Promise = require("bulebird");
// On web browsers.
window.Promsie = Promise;
// On non-web browsers.
global.Promise = Promise;

Usage

Installation

npm install kaphein-js-signal

Import

CommonJS style

const { Signal } = require("kaphein-js-signal");

ECMAScript module style

import { Signal } from "kaphein-js-signal";

Examples

(async () =>
{
    try
    {
        // Throws SingalTimeoutError after 2000ms.
        const signal = new Signal(2000);

        // Waits for a signal.
        const result = await signal;

        // Calls signal.emit({ foo : "foo" }) somewhere.

        // Outputs { foo : "foo" }
        console.debug(result);
    }
    catch(error)
    {
        // Throws an instance of SingalTimeoutError on timeout.
    }
})();