Nacho Portmanteau Meltdown

    wait-signal
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.2 • Public • Published

    EXAMPLE

    JAVASCRIPT

    const WaitEvent = require('wait-signal');
    
    const ready1 = new WaitEvent();
    const ready2 = new WaitEvent();
    
    (async() => {
        try {
            let result = await ready1.wait();
            console.log("WAIT-1 SUCCESS: ", result);
        }catch(e){
            console.log("WAIT-1 THROW: ", e.message);
        }
    })();
    
    (async() => {
        ready1.wait((result, e) => {
            if(e) {
                console.log("WAIT-2 THROW: ", e.message);
                return ;
            }
            console.log("WAIT-2 SUCCESS: ", result);
        });
    })();
    
    ready1.signal("*SIGNAL*");
    ready2.throw(new Error('Test Throw Message'));
    
    (async() => {
        try {
            let result = await ready2.wait();
            console.log("WAIT-3 SUCCESS: ", result);
        }catch(e){
            console.log("WAIT-3 THROW: ", e.message);
        }
    })();
    
    (async() => {
        ready2.wait((result, e) => {
            if(e) {
                console.log("WAIT-4 THROW: ", e.message);
                return ;
            }
            console.log("WAIT-4 SUCCESS: ", result, " / ", e);
        });
    })();

    TYPESCRIPT

    import WaitEvent from 'wait-signal'
    
    const ready1 = new WaitEvent<string>();
    const ready2 = new WaitEvent<string>();
    
    (async() => {
        try {
            let result: string = await ready1.wait();
            console.log("WAIT-1 SUCCESS: ", result);
        }catch(e){
            console.log("WAIT-1 THROW: ", e.message);
        }
    })();
    
    (async() => {
        ready1.wait((result: string, e) => {
            if(e) {
                console.log("WAIT-2 THROW: ", e.message);
                return ;
            }
            console.log("WAIT-2 SUCCESS: ", result);
        });
    })();
    
    ready1.signal("*SIGNAL*");
    ready2.throw(new Error('Test Throw Message'));
    
    (async() => {
        try {
            let result: string = await ready2.wait();
            console.log("WAIT-3 SUCCESS: ", result);
        }catch(e){
            console.log("WAIT-3 THROW: ", e.message);
        }
    })();
    
    (async() => {
        ready2.wait((result: string, e) => {
            if(e) {
                console.log("WAIT-4 THROW: ", e.message);
                return ;
            }
            console.log("WAIT-4 SUCCESS: ", result, " / ", e);
        });
    })();

    LICENSE

    This software may be modified and distributed under the terms of the Apache License 2.0. See the LICENSE file for details.

    Keywords

    none

    Install

    npm i wait-signal

    DownloadsWeekly Downloads

    7

    Version

    1.1.2

    License

    Apache-2.0

    Unpacked Size

    32.6 kB

    Total Files

    19

    Last publish

    Collaborators

    • jc-lab