Socket
Socket
Sign inDemoInstall

simple-tasks

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

6

index.js

@@ -10,2 +10,8 @@ // Generated by CoffeeScript 1.8.0

var args, e, func;
if (task === 'stop') {
process.send({
status: stopped
});
process.exit();
}
try {

@@ -12,0 +18,0 @@ func = eval('(' + task.task + ')');

2

package.json
{
"name": "simple-tasks",
"version": "1.0.1",
"version": "1.0.2",
"description": "Easy way to dispatch your functions to a separate process making them truly async",

@@ -5,0 +5,0 @@ "repository": {

@@ -12,12 +12,15 @@ # node-simple-tasks

### Usage
Each require('simple-stasks') call created a new worker thread and returns a task queue object for it:
Each `require('simple-stasks')` call created a new worker thread and returns a task queue object for it:
*class* **Queue**
    *method* **push**( `function`, `arg1`, `arg2`, ..., `callback`)
    *method*  **push**( `function`, `arg1`, `arg2`, ..., `callback`)
      Schedules `function` to be called with `arg1`, `arg2`, ... arguments in worker process context. The `callback` function will be called when task is finished. `callback` can be null.
Schedules `function` to be called with `arg1`, `arg2`, ..., `resultCallback` arguments under worker process context. The `callback` function will be called when task is finished, it is a required argument (last argument of **push()** is always interpreted as callback), but you can pass `null` explicitly instead of it (see first example). The `resultCallback` argument which is always passed to `function` can be used to return data back to main thread: simply pass the data as the first argument and it will be delivered as `callback` first argument.
    *method*  **stop**()
Cancels all pending tasks and stops worker process.
### Example
### Examples
```javascript

@@ -46,1 +49,13 @@ var tasks = require('simple-tasks');

```
You can use worker function callback argument for passing data back from the worker process to main. Apart from user provided arguments, the worker process will always pass result callback function to the worker thread. The callback takes one argument which will be passed back to main thread.
```javascript
var tasks = require('simple-tasks');
function approximatePi(callback) {
callback(3.1416);
}
tasks.push(approximatePi, function(pi) {
console.log('The approximate value of Pi is: ' + pi);
});
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc