@@ -42,6 +42,8 @@ var p = new Parallel([1, 2, 3, 4, 5]);
4242console .log (p .data ); // prints [1, 2, 3, 4, 5]
4343```
4444
45+ *******
46+
4547#### ` spawn(fn) `
4648This function will spawn a new process on a worker thread. Pass it the function you want to call. Your
4749function will receive one argument, which is the current data. The value returned from your spawned function will
@@ -66,6 +68,8 @@ p.spawn(function (data) {
6668});
6769```
6870
71+ *******
72+
6973#### ` map(fn) `
7074Map will apply the supplied function to every element in the wrapped data. Parallel will spawn one worker for
7175each array element in the data, or the supplied maxWorkers argument. The values returned will be stored for
@@ -91,6 +95,8 @@ p.map(fib).then(log)
9195// Logs the first 7 Fibonnaci numbers, woot!
9296```
9397
98+ *******
99+
94100#### ` reduce(fn) `
95101Reduce applies an operation to every member of the wrapped data, and returns a scalar value produced by the operation.
96102Use it for combining the results of a map operation, by summing numbers for example. This takes a reducing function,
@@ -113,6 +119,8 @@ p.require(factorial)
113119p .map (function (n ) { return Math .pow (10 , n); }).reduce (add).then (log);
114120```
115121
122+ *******
123+
116124#### ` then(success, fail) `
117125The functions given to ` then ` are called after the last requested operation has finished.
118126` success ` receives the resulting data object, while ` fail ` will receive an error object.
@@ -135,6 +143,8 @@ p.map(dbl).map(dbl).map(dbl).then(function (data) {
135143p .map (function (n ) { return Math .pow (10 , n); }).reduce (add).then (log);
136144```
137145
146+ *******
147+
138148#### ` require(state) `
139149If you have state that you want to share between your main thread and the worker threads, this is how. Require
140150takes either a string or a function. A string should point to a file name.
0 commit comments