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

1.0.1 • Public • Published

deasynchronize

Run asynchronous or synchronous function in subprocess and return result synchronously

Install

npm i -S deasynchronize

Usage

const result = deasynchronize(1, 2, async (a, b) => {
    // This is not a closure!
    await new Promise(resolve => setTimeout(resolve, 0));
    return `async result ${a + b}`;
});
console.log(result); // => 'async result 3'

API

deasynchronize(...argsany[], f: (...args: any[]) => any)string

Function f is not a closure and do not has access to parent scope, it runs in subprocess. You should require all dependencies inside this function. Result will be converted to string.

const result = deasynchronize(async () => {
    // This is not a closure!
    const os = require('os');
    return os.platform();
});

It is possible to pass parameters to function:

const result = deasynchronize('meow', async sound => {
    // This is not a closure!
    return `Incoming sound is ${sound}`;
});
console.log(result); // => 'Incoming sound is meow'

Remember, this function is not a closure!

/deasynchronize/

    Package Sidebar

    Install

    npm i deasynchronize

    Weekly Downloads

    7

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    11.3 kB

    Total Files

    9

    Last publish

    Collaborators

    • iamthes