1 | control.async
|
2 | =============
|
3 |
|
4 | [![Build Status](https://secure.travis-ci.org/folktale/control.async.png?branch=master)](https://travis-ci.org/folktale/control.async)
|
5 | [![NPM version](https://badge.fury.io/js/control.async.png)](http://badge.fury.io/js/control.async)
|
6 | [![Dependencies Status](https://david-dm.org/folktale/control.async.png)](https://david-dm.org/folktale/control.async)
|
7 | [![experimental](http://hughsk.github.io/stability-badges/dist/experimental.svg)](http://github.com/hughsk/stability-badges)
|
8 |
|
9 |
|
10 | Operations for asynchronous control flow.
|
11 |
|
12 |
|
13 | ## Example
|
14 |
|
15 | ```js
|
16 | var fs = require('fs')
|
17 | var async = require('control.async')
|
18 |
|
19 | var read = async.liftNode(fs.readFile)
|
20 |
|
21 | var files = async.parallel([ read('foo.txt', 'utf-8')
|
22 | , read('bar.txt', 'utf-8')
|
23 | , read('baz.txt', 'utf-8')])
|
24 |
|
25 | var concatenated = files.chain(function(xs){ return xs.join('') })
|
26 |
|
27 | // Futures are pure, so you need to actually run the action to get
|
28 | // the effects.
|
29 | concatenated.fork(
|
30 | function(error){ throw error }
|
31 | , function(value){ console.log(value) }
|
32 | )
|
33 | ```
|
34 |
|
35 |
|
36 | ## Installing
|
37 |
|
38 | The easiest way is to grab it from NPM. If you're running in a Browser
|
39 | environment, you can use [Browserify][]
|
40 |
|
41 | $ npm install control.async
|
42 |
|
43 |
|
44 | ### Using with CommonJS
|
45 |
|
46 | If you're not using NPM, [Download the latest release][release], and require
|
47 | the `control.async.umd.js` file:
|
48 |
|
49 | ```js
|
50 | var Async = require('control.async')
|
51 | ```
|
52 |
|
53 |
|
54 | ### Using with AMD
|
55 |
|
56 | [Download the latest release][release], and require the `control.async.umd.js`
|
57 | file:
|
58 |
|
59 | ```js
|
60 | require(['control.async'], function(Async) {
|
61 | ( ... )
|
62 | })
|
63 | ```
|
64 |
|
65 |
|
66 | ### Using without modules
|
67 |
|
68 | [Download the latest release][release], and load the `control.async.umd.js`
|
69 | file. The properties are exposed in the global `Async` object:
|
70 |
|
71 | ```html
|
72 | <script src="/path/to/control.async.umd.js"></script>
|
73 | ```
|
74 |
|
75 |
|
76 | ### Compiling from source
|
77 |
|
78 | If you want to compile this library from the source, you'll need [Git][],
|
79 | [Make][], [Node.js][], and run the following commands:
|
80 |
|
81 | $ git clone git://github.com/folktale/control.async.git
|
82 | $ cd control.async
|
83 | $ npm install
|
84 | $ make bundle
|
85 |
|
86 | This will generate the `dist/control.async.umd.js` file, which you can load in
|
87 | any JavaScript environment.
|
88 |
|
89 |
|
90 | ## Documentation
|
91 |
|
92 | You can [read the documentation online][docs] or build it yourself:
|
93 |
|
94 | $ git clone git://github.com/folktale/control.async.git
|
95 | $ cd control.async
|
96 | $ npm install
|
97 | $ make documentation
|
98 |
|
99 | Then open the file `docs/index.html` in your browser.
|
100 |
|
101 |
|
102 | ## Platform support
|
103 |
|
104 | This library assumes an ES5 environment, but can be easily supported in ES3
|
105 | platforms by the use of shims. Just include [es5-shim][] :)
|
106 |
|
107 |
|
108 | ## Licence
|
109 |
|
110 | Copyright (c) 2013-2014 Quildreen Motta.
|
111 |
|
112 | Released under the [MIT licence](https://github.com/folktale/control.async/blob/master/LICENCE).
|
113 |
|
114 |
|
115 | [Fantasy Land]: https://github.com/fantasyland/fantasy-land
|
116 | [Browserify]: http://browserify.org/
|
117 | [release]: https://github.com/folktale/control.async/releases/download/v0.0.0/control.async-0.0.0.tar.gz
|
118 | [Git]: http://git-scm.com/
|
119 | [Make]: http://www.gnu.org/software/make/
|
120 | [Node.js]: http://nodejs.org/
|
121 | [es5-shim]: https://github.com/kriskowal/es5-shim
|
122 | [docs]: http://folktale.github.io/control.async
|