Giter Club home page Giter Club logo

funwork's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.