deasynchronize
Run asynchronous or synchronous function in subprocess and return result synchronously
Last updated 4 months ago by iamthes .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install deasynchronize 
SYNC missed versions from official npm registry.

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(...args: any[], 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!

Current Tags

  • 1.0.1                                ...           latest (4 months ago)

2 Versions

  • 1.0.1                                ...           4 months ago
  • 1.0.0                                ...           4 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |