asyncifyjs
Make CPU intensive code asynchronous just like Javascript IO call
Last updated 5 years ago by maiah .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install asyncifyjs 
SYNC missed versions from official npm registry.

asyncify

Make your non-IO JavaScript code asynchronous non-blocking just like Node.js non-blocking IO. This is perfect for CPU intensive code.

Installation

npm install --save asyncifyjs

Usage

const asyncify = require('asyncifyjs');

function fib(num) {
    if (num === 0) return 0;
    else if (num === 1) return 1;
    else return fib(num - 1) + fib(num - 2);
}

const fibAsync = asyncify(fib);

fibAsync(32, function (res) {
    console.log('2. The result is', res);
});

fibAsync(15, function (res) {
    console.log('2. The result is', res);
});

Or using promises:

fibAsync(20).then(function (res) {
    console.log('The result is', res);
});

fibAsync(10).then(function (res) {
    console.log('The result is', res);
});

License

The MIT License (MIT)

Copyright (c) 2015 Maiah Macariola

Current Tags

  • 1.1.0                                ...           latest (5 years ago)

3 Versions

  • 1.1.0                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |