Skip to content

A waitable object for Javascript based on ECMAScript 6 Promise.

License

Notifications You must be signed in to change notification settings

Hydrawisk793/kaphein-js-signal

Repository files navigation

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.
    }
})();

About

A waitable object for Javascript based on ECMAScript 6 Promise.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published