FunWork - Make functions become non-blocking thougth workers.
Brief
CPU intensive calculations blocks event-loop while its execution.
Workers solve this problem, but require some extra plumbing.
FunWork combines workers and nextTick() (deasync) to avoid the mess of dealing with workers by simply converting a function into a "worker function".
The only restriction is that it must be a pure function because workers haven't access to the master process scope.
That is: Source functions haven't access to scope, context and cannot modify its arguments (or cause any side effect in any way).
Installation:
npm install [--save] funwork
Usage:
var funwork = require("funwork");
...
var nonBlockingFn = funwork(blockingFn);
Example:
var funwork = ; // Blocking pure function { // Do some expensive calculation: for var i = 0; i< 1000000000; i++ x--; ; return 2 * x * i; } var f = ; ; // Function calls that will be executed in backgrond thought workers: console; console;
Contributing
If you are interested in contributing with this project, you can do it in many ways:
-
Creating and/or mantainig documentation.
-
Implementing new features or improving code implementation.
-
Reporting bugs and/or fixing it.
-
Sending me any other feedback.
-
Whatever you like...
Please, contact-me, open issues or send pull-requests thought this project GIT repository