Skip to content

SamyPesse/jobworker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JobWorker

NPM version Build Status

JobWorker is an utility to create background job workers. This module provides a transport to work with WebWorker, but can also be transport agnostic.

Installation

$ npm install jobworker

Usage

Create a web-worker "myworker.js" using:

var jw = require("jobworker");

var server = new jw.WebWorkerServer();

// Register some methods
server.register({
    // Task can be sync
    hello: function() {
        return "World";
    },

    // Or async:
    testAsync: function() {
        return doSomethingSync()
        .then(function() {
            // it should return a promise
        });
    }
});

// Run the worker
server.start();

And in your application, access the web-worker using:

var jw = require("jobworker");

var worker = new jw.WebWorkerClient("myworker.js");


// Call a method
worker.callMethod("hello")
.then(function(msg) {

});

// Or create a binded nethod:
var testAsync = worker.method("testAsync");

Custom Transport

Events and WebWorker are good examples on how to write a custom transport.

About

WebWorker background jobs worker

Resources

License

Stars

Watchers

Forks

Packages

No packages published