11# Promise
22The Promise module in Lua. Simple, Fast and ES6 Promises full supported/compatibled.
33
4- about ES6 Promises see here: [ Promise in MDN] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise )
4+ About ES6 Promises see here: [ Promise in MDN] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise )
55
6- a chinese document at here: [ The Promise's World] ( http://blog.csdn.net/aimingoo/article/details/47401961 )
6+ A chinese document at here: [ The Promise's World] ( http://blog.csdn.net/aimingoo/article/details/47401961 )
7+
8+ ### Table of Contents
79
8- ###Table of Contents
910* [ Install & ; Usage] ( #install--usage )
1011* [ Interface] ( #interface )
1112* [ testcase or samples] ( #testcase-or-samples )
1213* [ History] ( #history )
1314
1415
1516# Install & Usage
16- download the Promise.lua file and put into lua search path or current directory, and load it as a file module from lua.
17+ Download the file ` Promise.lua ` and put it into lua search path or current directory, and load as module from lua.
18+
19+ Or use luarocks and require as module:
1720
18- or use luarocks and require as module:
1921``` bash
2022> luarocks install promise-es6
2123```
2224
23- and, use Promise.new() or use Promise.xxx method to get promise object.
25+ and, use ` Promise.new() ` or use ` Promise.xxx ` method to get promise object.
26+
2427``` lua
2528Promise = require (' Promise' )
2629
@@ -38,50 +41,59 @@ end):andThen(..) -- more
3841
3942# Interface
4043
41- for the Promsie, call with '.':
44+ * ** For the Promsie class, call with '.'**
45+
46+ ** Promise.new(executor)**
4247
43- > - Promise.new(executor);
4448> ``` lua
4549> promise = Promise .new (function (resolve , reject ) .. end );
4650> ` ` `
47- ```
48- >
49- > - Promise.all(array);
50- ```lua
51- promise = Promise.all(array) -- a table as array
52- ```
53- >
54- >- Promise.race(array) -- a table as array
55- ```lua
56- promise = Promise.race(array) -- a table as array
57- ```
58- >
59- > - Promise.reject(reason)
60- ``` lua
61- promise = Promise .reject (reason ); -- reason is anything
62- ```
63- >
64- > - Promise.resolve(value)
65- ``` lua
66- promise = Promise .resolve (value );
67- promise = Promise .resolve (thenable );
68- promise = Promise .resolve (promise );
69- ```
7051
71- for promise instance, call with ':':
72- > - promise: andThen (onFulfilled, onRejected)
73- ``` lua
74- promise2 = promise :andThen (functoin (value ) ... end );
75- promise2 = promise :andThen (nil , functoin (reson ) ... end );
76- ```
77- >
78- > - promise: catch (onRejected)
79- ``` lua
80- promise2 = promise :catch (functoin (reson ) ... end )
81- ```
52+ ** Promise .all (array )**
53+
54+ > ` ` `
55+ > promise = Promise .all (array ) -- a table as array
56+ > ` ` `
57+
58+ ** Promise .race (array )**
59+
60+ > ` ` ` lua
61+ > promise = Promise .race (array ) -- a table as array
62+ > ` ` `
63+
64+ ** Promise .reject (reason )**
65+
66+ > ` ` ` lua
67+ > promise = Promise .reject (reason ); -- reason is anything
68+ > ` ` `
69+
70+ ** Promise .resolve (value )**
71+
72+ > ` ` ` lua
73+ > promise = Promise .resolve (value );
74+ > promise = Promise .resolve (thenable );
75+ > promise = Promise .resolve (promise );
76+ > ` ` `
77+
78+ * ** For promise instance , call with ' :' **
79+
80+ ** promise :andThen (onFulfilled , onRejected )**
81+
82+ > ` ` ` lua
83+ > promise2 = promise :andThen (functoin (value ) ... end );
84+ > promise2 = promise :andThen (nil , functoin (reson ) ... end );
85+ > ` ` `
86+
87+ ** promise :catch (onRejected )**
88+
89+ > ` ` ` lua
90+ > promise2 = promise :catch (functoin (reson ) ... end )
91+ > ` ` `
8292
8393# testcase or samples
94+
8495This is a base testcase :
96+
8597` ` ` lua
8698---
8799--- from testcase/t_base_test.lua
@@ -117,21 +129,27 @@ Promise.all(promises)
117129 print (reson )
118130 end )
119131```
132+
120133# History
121- -- 2017.04.26 release v1.2, fix some bugs
122134
123- > - fix bug: value deliver on promise chain, about issue-#3, thanks for @stakira
124- > - ignore rewrite promised value
135+ * 2017.04.26 release v1.2, fix some bugs
136+
137+ ```
138+ - fix bug: value deliver on promise chain, about issue-#3, thanks for @stakira
139+ - ignore rewrite promised value
140+ ```
125141
126- -- 2015.10.29 release v1.1, fix some bugs
142+ * 2015.10.29 release v1.1, fix some bugs
127143
128- > - update testcases
129- > - update: add .catch() for promised string
130- > - update: protect call in .new method
131- > - fix bug: resolver values when multi call .then()
132- > - fix bug: non standard .reject() implement
133- > - fix bug: some error in .all() and .race() methods
144+ ```
145+ - update testcases
146+ - update: add .catch() for promised string
147+ - update: protect call in .new method
148+ - fix bug: resolver values when multi call .then()
149+ - fix bug: non standard .reject() implement
150+ - fix bug: some error in .all() and .race() methods
151+ ```
134152
135- -- 2015.08.10 release v1.0.1, full testcases, minor fix and publish on github
153+ * 2015.08.10 release v1.0.1, full testcases, minor fix and publish on github
136154
137- -- 2015.03 release v1.0.0
155+ * 2015.03 release v1.0.0
0 commit comments