paratask-promises

所属分类:超算/并行计算
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2015-07-31 06:24:11
上 传 者sh-1993
说明:  Paratask是一种工具,它将使用多进程编程的全部潜力并行执行Node.js代码。与...相反...,
(Paratask is a tool that will execute your Node.js code in parallel using the full potential of multi-process programming. In contrast to asynchronous task management, Paratask will create a child Node.js process in which your task function will live .)

文件列表:
.npmignore (12, 2015-07-30)
.travis.yml (120, 2015-07-30)
Gruntfile.js (304, 2015-07-30)
build_tests/ (0, 2015-07-30)
build_tests/execution_error_test.js (1520, 2015-07-30)
build_tests/input_validation_test.js (2701, 2015-07-30)
build_tests/legacy_test.js (722, 2015-07-30)
build_tests/use_promise_test.js (1798, 2015-07-30)
lib/ (0, 2015-07-30)
lib/index.js (12865, 2015-07-30)
lib/promise.js (4333, 2015-07-30)
lib/shared_data/ (0, 2015-07-30)
lib/task_executor.js (5712, 2015-07-30)
lib/utils.js (61066, 2015-07-30)
license (1076, 2015-07-30)
package.json (1128, 2015-07-30)
tests/ (0, 2015-07-30)
tests/async_heavy_test.js (4744, 2015-07-30)
tests/async_light_test.js (2092, 2015-07-30)
tests/async_timeout_test.js (1724, 2015-07-30)
tests/paratask_heavy_test.js (5664, 2015-07-30)
tests/paratask_light_test.js (2383, 2015-07-30)
tests/paratask_timeout_test.js (1757, 2015-07-30)
tests/process_nextTick_heavy_test.js (4915, 2015-07-30)
tests/process_nextTick_light_test.js (2246, 2015-07-30)
tests/process_nextTick_timeout_test.js (1871, 2015-07-30)

# Paratask - Node Parallel Process Manager [![Build Status](https://secure.travis-ci.org/IvanDimanov/paratask-promises.png?branch=master)](http://travis-ci.org/IvanDimanov/paratask-promises) [![NPM version](https://badge.fury.io/js/paratask-promises.png)](http://badge.fury.io/js/paratask-promises) Paratask is a tool that will execute your code in __parallel__ using the full potential of multi-process programming. In contrast to asynchronous task management, Paratask will create a child Node/io.js process in which your task function will 'live'. __Note:__ Scope dependency injection is at your service. More into in the examples below. __Note:__ This modules embraces the __Promises/A+__ standard. If you're more into ES5 "callback" style you can use [paratask](https://github.com/IvanDimanov/paratask) ## Install You can install Paratask __Promises/A+__ with the Node Package Manager: ```shell npm install paratask-promises ``` or by getting it from [this repo](https://github.com/IvanDimanov/paratask-promises). ## Dependencies Paratask uses only native Node/io.js modules that do not need additional installation: `fs` and `child_process`. ## Custom Promise lib You like to use your own Promise constructor or 3rd party alternative? No problem, just type: ```javascript var paratask = require('paratask-promises'); paratask.usePromise( require('bluebird').Promise ); // or paratask.usePromise( require('q').Promise ); // or paratask.usePromise( require('when').Promise ); // or paratask.usePromise( require('rsvp').Promise ); ``` Thanks to [machinewu](https://github.com/machinewu) for the great suggestion. ### Example: Parallel calculation Both `task_1` and `task_2` will fork a new Node/io.js process and will run __concurrently__. When both call `resolve()`, the final results will be printed in the console. __Note:__ `scope` property is your dependency injector. Can only be a valid `JSON.parse()` value (i.e. no functions allowed). ```javascript var paratask = require('paratask-promises'); var task_1 = { fork: function (resolve) { // Some calculation using the 'count' scope var var result = count * 10; resolve(result); }, scope: { count: 10 } }; var task_2 = { fork: function (resolve) { // Some calculation using the 'count' scope var var result = count * 10; resolve(result); }, scope: { count: 20 } }; paratask([ task_1, task_2 ]) .then(function (results) { console.log( results ); // [100, 200], 1st task result will be always the 1st in the results array even if completed last }); ``` ### Example: Error handling Both `task_1` and `task_2` will fork a new process but when `task_2` call `reject('Error message')` both processes will be killed and the final `.then()` will be executed. __Note:__ `scope` property is optional. ```javascript var paratask = require('paratask-promises'); var task_1 = { fork: function (resolve) { var count = 100000; var factorial = 1; while (--count) factorial *= count; resolve(factorial); } }; var task_2 = { fork: function (resolve, reject) { reject('Error message'); } }; paratask([ task_1, task_2 ]) .catch(function (error) { console.log( error ); // 'Error message' }); ``` ## Comparison tests A palette of comparison tests between `paratask()`, `async.parallel()`, and `process.nextTick()` are available in `./tests` folder. ### Heavy calculation test: ```shell node tests/async_heavy_test.js ``` ```shell node tests/process_nextTick_heavy_test.js ``` ```shell node tests/paratask_heavy_test.js ``` ## Conclusion Paratask is great when you have several time consuming task functions with few external dependencies. In such cases, __multi-processing__ is the best approach. When you want to manage several relevantly quick functions with asynchronous logic, [async](https://github.com/caolan/async) will handle it with beauty.

近期下载者

相关文件


收藏者