Skip to content

Commit b95135a

Browse files
MaXwell Falsteinamilajack
authored andcommitted
Update README (#158)
* Add First Timers Only Add [![first-timers-only](http://img.shields.io/badge/first--timers--only-friendly-blue.svg?style=flat-square)](http://www.firsttimersonly.com/) for First Timers Only * MD Reformatting # ## ### #### --- * Update README.md * Add Contributors and License
1 parent 7eccbcb commit b95135a

File tree

1 file changed

+85
-39
lines changed

1 file changed

+85
-39
lines changed

README.md

Lines changed: 85 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
1-
Parallel.js
2-
===========
1+
# Parallel.js
2+
33
[![Build Status](https://travis-ci.org/parallel-js/parallel.js.svg?branch=master)](https://travis-ci.org/parallel-js/parallel.js)
44
[![NPM version](https://badge.fury.io/js/paralleljs.svg)](http://badge.fury.io/js/paralleljs)
55
[![Dependency Status](https://img.shields.io/david/parallel-js/parallel.js.svg)](https://david-dm.org/parallel-js/parallel.js)
66
[![npm](https://img.shields.io/npm/dm/paralleljs.svg?maxAge=2592000)]()
7+
[![first-timers-only](http://img.shields.io/badge/first--timers--only-friendly-blue.svg?style=flat-square)](http://www.firsttimersonly.com/)
78

8-
9-
_Easy Parallel Computing with Javascript_
9+
**Easy Parallel Computing with Javascript**
1010

1111
> Please note that version 0.2.1 is 2 years old
1212
13-
> **Update: September 2016**: New forces are put in place to drive the code forward.
13+
**Update: September 2016**
14+
15+
> New forces are put in place to drive the code forward.
16+
17+
---
18+
19+
Parallel.js is a library for to make parallel computing in Javascript simple. It works in Node.js and in the Web Browser.
1420

15-
Parallel.js is a library making JavScript parallel computing simple.
16-
Parallel.js works in Node.js and in the web browser for client side, server side or a mixture of client and server side compute.
17-
Parallel.js takes advantage of Web Workers for the web, and child processes for Node.
21+
Parallel takes advantage of Web Workers for the web, and child processes for Node.
1822

19-
# Installation
23+
---
24+
25+
## Installation
2026

2127
You can download the raw javascript file [here](https://raw.github.com/adambom/parallel.js/master/lib/parallel.js)
2228

2329
Just include it via a script tag in your HTML page
2430

25-
Parallel.js is also available as a node module:
31+
**Parallel.js is also available as a node module**
2632

2733
```bash
2834
npm install paralleljs --save
2935
```
3036

31-
# Usage
37+
## Usage
3238

33-
#### `Parallel(data, opts)`
39+
### `Parallel(data, opts)`
3440

3541
This is the constructor. Use it to new up any parallel jobs. The constructor takes an array of data you want to
3642
operate on. This data will be held in memory until you finish your job, and can be accessed via the `.data` attribute
@@ -39,32 +45,36 @@ of your job.
3945
The object returned by the `Parallel` constructor is meant to be chained, so you can produce a chain of
4046
operations on the provided data.
4147

42-
*Arguments*
48+
**Arguments**
49+
4350
* `data`: This is the data you wish to operate on. Will often be an array, but the only restrictions are that your values are serializable as JSON.
4451
* `options` (optional): Some options for your job
45-
* `evalPath` (optional): This is the path to the file eval.js. This is required when running in node, and required for some browsers (IE 10) in order to work around cross-domain restrictions for web workers. Defaults to the same location as parallel.js in node environments, and `null` in the browser.
46-
* `maxWorkers` (optional): The maximum number of permitted worker threads. This will default to 4, or the number of cpus on your computer if you're running node
47-
* `synchronous` (optional): If webworkers are not available, whether or not to fall back to synchronous processing using `setTimeout`. Defaults to `true`.
52+
* `evalPath` (optional): This is the path to the file eval.js. This is required when running in node, and required for some browsers (IE 10) in order to work around cross-domain restrictions for web workers. Defaults to the same location as parallel.js in node environments, and `null` in the browser.
53+
* `maxWorkers` (optional): The maximum number of permitted worker threads. This will default to 4, or the number of cpus on your computer if you're running node
54+
* `synchronous` (optional): If webworkers are not available, whether or not to fall back to synchronous processing using `setTimeout`. Defaults to `true`.
4855

49-
*Example*
56+
**Example**
5057

5158
```js
5259
const p = new Parallel([1, 2, 3, 4, 5]);
5360

5461
console.log(p.data); // prints [1, 2, 3, 4, 5]
5562
```
5663

57-
*******
64+
---
65+
66+
### `spawn(fn)`
5867

59-
#### `spawn(fn)`
6068
This function will spawn a new process on a worker thread. Pass it the function you want to call. Your
6169
function will receive one argument, which is the current data. The value returned from your spawned function will
6270
update the current data.
6371

64-
*Arguments*
72+
**Arguments**
73+
6574
* `fn`: A function to execute on a worker thread. Receives the wrapped data as an argument. The value returned will be assigned to the wrapped data.
6675

67-
*Example*
76+
**Example**
77+
6878
```js
6979
const p = new Parallel('forwards');
7080

@@ -81,17 +91,20 @@ p.spawn(data => {
8191
});
8292
```
8393

84-
*******
94+
---
95+
96+
### `map(fn)`
8597

86-
#### `map(fn)`
8798
Map will apply the supplied function to every element in the wrapped data. Parallel will spawn one worker for
8899
each array element in the data, or the supplied maxWorkers argument. The values returned will be stored for
89100
further processing.
90101

91-
*Arguments*
102+
**Arguments**
103+
92104
* `fn`: A function to apply. Receives the wrapped data as an argument. The value returned will be assigned to the wrapped data.
93105

94-
*Example*
106+
**Example**
107+
95108
```js
96109
const p = new Parallel([0, 1, 2, 3, 4, 5, 6]);
97110
const log = function () { console.log(arguments); };
@@ -108,17 +121,20 @@ p.map(fib).then(log)
108121
// Logs the first 7 Fibonnaci numbers, woot!
109122
```
110123

111-
*******
124+
---
125+
126+
### `reduce(fn)`
112127

113-
#### `reduce(fn)`
114128
Reduce applies an operation to every member of the wrapped data, and returns a scalar value produced by the operation.
115129
Use it for combining the results of a map operation, by summing numbers for example. This takes a reducing function,
116130
which gets an argument, `data`, an array of the stored value, and the current element.
117131

118-
*Arguments*
132+
**Arguments**
133+
119134
* `fn`: A function to apply. Receives the stored value and current element as argument. The value returned will be stored as the current value for the next iteration. Finally, the current value will be assigned to current data.
120135

121-
*Example*
136+
**Example**
137+
122138
```js
123139
const p = new Parallel([0, 1, 2, 3, 4, 5, 6, 7, 8]);
124140

@@ -132,17 +148,20 @@ p.require(factorial)
132148
p.map((n => Math.pow(10, n)).reduce(add).then(log);
133149
```
134150
135-
*******
151+
---
152+
153+
### `then(success, fail)`
136154
137-
#### `then(success, fail)`
138155
The functions given to `then` are called after the last requested operation has finished.
139156
`success` receives the resulting data object, while `fail` will receive an error object.
140157
141-
*Arguments*
158+
**Arguments**
159+
142160
- `success`: A function that gets called upon successful completion. Receives the wrapped data as an argument.
143161
- `failure` (optional): A function that gets called if the job fails. The function is passed an error object.
144162
145-
*Example*
163+
**Example**
164+
146165
```js
147166
const p = new Parallel([1, 2, 3]);
148167

@@ -163,15 +182,17 @@ p
163182
.then(log);
164183
```
165184
166-
*******
185+
---
186+
187+
### `require(state)`
167188
168-
#### `require(state)`
169189
If you have state that you want to share between your main thread and the worker threads, this is how. Require
170190
takes either a string or a function. A string should point to a file name. Note that in order to
171191
use ```require``` with a file name as an argument, you have to provide the evalPath property in the options
172192
object.
173193
174-
*Example*
194+
**Example**
195+
175196
```js
176197
let p = new Parallel([1, 2, 3], { evalPath: 'https://raw.github.com/adambom/parallel.js/master/lib/eval.js' });
177198

@@ -185,15 +206,20 @@ p.require('blargh.js');
185206

186207
p.map(d => blargh(20 * cubeRoot(d)));
187208
```
188-
#### Passing environement to functions
209+
210+
---
211+
212+
## Passing environement to functions
213+
189214
You can pass data to threads that will be global to that worker. This data will be global in each called function.
190215
The data will be available under the `global.env` namespace. The namespace can be configured by passing the
191216
`envNamespace` option to the `Parallel` constructor. The data you wish to pass should be provided as the `env` option
192217
to the parallel constructor.
193218
194219
Important: Globals can not be mutated between threads.
195220
196-
*Example*
221+
**Example**
222+
197223
```js
198224
let p = new Parallel([1, 2, 3], {
199225
env: {
@@ -215,5 +241,25 @@ p = new Parallel([1, 2, 3], {
215241
p.map(d => d * global.parallel.a);
216242
```
217243
218-
# Compatibility
244+
---
245+
246+
## Compatibility
247+
219248
[![browser support](https://ci.testling.com/adambom/parallel.js.png)](https://ci.testling.com/adambom/parallel.js)
249+
250+
---
251+
252+
## Contributors
253+
254+
Parallel.js is made up of four contributors:
255+
256+
[Adam Savitzky (Adam)](https://github.com/adambom)
257+
[Mathias Rangel Wulff (Mathias)](https://github.com/mathiasrw)
258+
[Amila Welihinda (amilajack)](https://github.com/amilajack)
259+
[MaXwell Falstein (MaX)](https://github.com/MaXwellFalstein)
260+
261+
---
262+
263+
## License
264+
265+
[Please find the license in the GitHub repository](https://github.com/parallel-js/parallel.js/blob/master/LICENSE).

0 commit comments

Comments
 (0)