npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

supertask

v2.1.0

Published

A task & queue environment ideal for distributed computing and execution

Downloads

37

Readme

supertask

Build Status Test Coverage

Supertask is a NodeJS task queue designed for parallel and cluster execution.

Supertask was designed to run tasks in parallel and enable for a connected interface to distribute tasks across a network or cluster. A task can either be a local JavaScript function or in form of source which is then compiled and sandboxed through the VM. It utilizes a double-ended queue to manage and execute given tasks.

Note that there is no underlying interface for parallelization or clustering and this module enables such features through tasks.

Installation

Note that Supertask requires ES6 and is designed to run on NodeJS 4.x and above.

npm install supertask

Usage

Create a new local task with a unique name. Note that a unique name is required for every task.

var Supertask = require('supertask');
var TaskManager = new Supertask();

var task = TaskManager.addLocal('taskname', function power(n, x, callback) {
    // n^x function
    callback(null, Math.pow(n,x));
});

Run task. You can pass arguments after name and before callback.

TaskManager.do('taskname', 2, 4, function callback(error, result) {
    console.log("2^4 is equal to", result);
});

Add a foreign task

// Source from network I/O etc.
var source = "module.exports = function power(n, x, callback) { callback(null, Math.pow(n,x)); }";
var task = TaskManager.addForeign('foreignPow', source);

Change permissions and globals of a task and precompilation

var Supertask = require('supertask');
var TaskManager = new Supertask();

// Source from network I/O etc.
var source = "module.exports = function cmtp(y, callback) { callback(null, y * gx); }";

var task = TaskManager.addForeign('globalMultiply', source);
task.permissions(Supertask.ST_MINIMAL); // Allows limited require, Buffer, etc.
// gx will be available globally
task.globals({ gx: 2 });
// Compile Task through VM
task.precompile();
// Call Task (similar to TaskManager.do)
task.do(8, function(error, result) {
    // arg[0] * gx = 8 * 2 = 16
    console.log(result);
    // Output: 16
});

Calling another task within a task.

...
// Source from network I/O etc.
var sourceF1 = "module.exports = function (a, b, callback) { callback(null, a*b); }";
var sourceF2 = "module.exports = function (a, b, callback) { this.call('multiply', a, b, callback); }";

TaskManager.addForeign('multiply', sourceF1);
var task = TaskManager.addForeign('Caller', source);
// Call Task (similar to TaskManager.do)
task.do(3, 7, function(error, result) {
    // 3 * 7
    console.log(result);
    // Output: 21
});

What's the difference between a Task and a Function?

Functions can't be shared within Clusters or networks in JS unlike many other types that can be trasferred in form of JSON. That's because of globals and closures. If we could ignore closures and instead stick to globals we can pass the source of these functions across a network and re-compile then through the VM Core Module provided with NodeJS from source. In fact require itself uses VM to process modules. Moreover Functions can be converted to Tasks but without closures. Although you can provide global variable access through Task#globals which can be useful at times.

*Above is an excerpt from Understanding Tasks You can read the entire guide here.

API & Documentation

Read more about tasks here.

API documentation is available here.

License

MIT © Schahriar SaffarShargh [email protected]