JSPM

funwork

0.0.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 3
    • Score
      100M100P100Q36402F
    • License GPL-3.0

    Make functions become non-blocking thougth workers.

    Package Exports

    • funwork

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (funwork) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    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 = require("funwork");
    
        // Blocking pure function
        function f0 (x){
            // Do some expensive calculation:
            for (var i = 0; i< 1000000000; i++) {
                x--;
            };
            return 2 * x * i;
        }
    
        var f = funwork(f0);
    
        setTimeout(function() {
            console.log ("Hello World!!!");
        }, 1300);
    
        // Function calls that will be executed in backgrond thought workers:
        console.log ("RESULT: ", f(7));
        console.log ("RESULT: ", f(22));
    

    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