Skip to content

Commit 3e1638a

Browse files
committed
fixup! Async.Promise: Fix/brush up the help document
1 parent ba152bf commit 3e1638a

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

doc/vital/Async/Promise.txt

+36-34
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ https://www.ecma-international.org/publications/standards/Ecma-262.htm
5151
REQUIREMENTS *Vital.Async.Promise-requirements*
5252

5353
|Vital.Async.Promise| requires |lambda| and |timers| features.
54-
So Vim 8.0 or later is required. Recent version of Neovim also supports them.
54+
So Vim 8.0 or later is required. The recent version of Neovim also supports
55+
them.
5556

5657

5758

@@ -74,9 +75,9 @@ Before explaining the detail of APIs, let's see actual examples.
7475
One of most simple asynchronous operation is a timer. It calls a specified
7576
callback when exceeding the timeout. "s:Promise.new" creates a new Promise
7677
object with given callback. In the callback, function "resolve" (and
77-
"reject" if needed) is passed. When asynchronous operation is done (in this
78-
case, when timer is expired), call "resolve" on success or call "reject" on
79-
failure.
78+
"reject" if needed) is passed. When the asynchronous operation is done (in
79+
this case, when the timer is expired), call "resolve" on success or call
80+
"reject" on failure.
8081

8182

8283
(2) Next tick *Vital.Async.Promise-example-next-tick*
@@ -92,8 +93,9 @@ Before explaining the detail of APIs, let's see actual examples.
9293
\.catch({err -> execute('echom err', '')})
9394
<
9495
By giving 0 to |timer_start()| as timeout, it waits for "next tick". It's the
95-
first time when Vim waits input. It means that Vim gives higher priority to
96-
user input and executes the script (in callback of |timer_start()|) after.
96+
first time when Vim waits for input. It means that Vim gives higher priority
97+
to user input and executes the script (in the callback of |timer_start()|)
98+
after.
9799

98100

99101
(3) Job *Vital.Async.Promise-example-job*
@@ -120,26 +122,26 @@ Before explaining the detail of APIs, let's see actual examples.
120122
endfunction
121123
<
122124
|job| is a feature to run commands asynchronously. But it is a bit hard to use
123-
because it requires callback. By wrapping it with Promise, it makes further
124-
easier to use commands and handle errors asynchronously.
125+
because it requires a callback. By wrapping it with Promise, it makes
126+
further easier to use commands and handle errors asynchronously.
125127

126-
s:read() is just a helper fnction which reads all output of channel from
127-
job. So it's not so important.
128+
s:read() is just a helper function which reads all output of channel from
129+
the job. So it's not so important.
128130

129131
Important part is "return ..." in s:sh(). It creates a Promise which starts
130132
a job and resolves when the given command has done. It calls resolve() when
131-
the command finished successfully with output from stdout, and calls
132-
reject() when the command failed with output from stderr.
133+
the command finished successfully with an output from stdout, and calls
134+
reject() when the command failed with an output from stderr.
133135

134-
"ls -l" can be executed as following:
136+
"ls -l" can be executed as follows:
135137
>
136138
call s:sh('ls', '-l')
137139
\.then({out -> execute('echo "Output: " . out', '')})
138140
\.catch({err -> execute('echo "Error: " . err', '')})
139141
<
140-
As more complex example, following code clones 4 repositories and shows a
141-
message when all of them has completed. When one of them fails, it shows an
142-
error message without waiting other operations.
142+
As the more complex example, following code clones 4 repositories and shows
143+
a message when all of them has completed. When one of them fails, it shows
144+
an error message without waiting for other operations.
143145
>
144146
call s:Promise.all([
145147
\ s:sh('git', 'clone', 'https://github.com/thinca/vim-quickrun.git'),
@@ -169,11 +171,11 @@ Before explaining the detail of APIs, let's see actual examples.
169171
\})
170172
<
171173
s:sh() and s:wait() are explained above. And .race() awaits one of given
172-
Promise objects has finished.
174+
Promise objects have finished.
173175

174176
The .race() awaits either s:sh(...) or s:wait(...) has completed or failed.
175177
It means that it clones Vim repository from GitHub via git command, but if
176-
it exceeds 10 seconds, it does not wait the clone operation anymore.
178+
it exceeds 10 seconds, it does not wait for the clone operation anymore.
177179

178180
By adding .then() and giving the result value (v:false or v:true here), you
179181
can know whether the asynchronous operation was timed out or not in
@@ -223,10 +225,10 @@ new({executor}) *Vital.Async.Promise.new()*
223225

224226
{executor} is a |Funcref| which represents how to create a Promise
225227
object. It is called _synchronously_. It receives two functions as
226-
parameters. First parameter is "resolve". It accepts one or zero
228+
parameters. The first parameter is "resolve". It accepts one or zero
227229
argument. By calling it in {executor}, new() returns a fulfilled
228-
Promise object. Second parameter is "reject". It also accepts one or
229-
zero argument. By calling it in {executor}, new() returns rejected
230+
Promise object. The second parameter is "reject". It also accepts one
231+
or zero argument. By calling it in {executor}, new() returns rejected
230232
Promise object.
231233
>
232234
" Fulfilled Promise object with 42
@@ -236,9 +238,9 @@ new({executor}) *Vital.Async.Promise.new()*
236238
let p = Promise.new({_, reject -> reject('ERROR!')})
237239
let p = Promise.new({-> execute('throw "ERROR!"')})
238240
<
239-
When other Promise object is passed to "resolve" or "reject" function
240-
call, new() returns a pending Promise object which awaits until the
241-
given other Promise object has finished.
241+
When another Promise object is passed to "resolve" or "reject"
242+
function call, new() returns a pending Promise object which awaits
243+
until the given other Promise object has finished.
242244

243245
If an exception is thrown in {executor}, new() returns a rejected
244246
Promise object with the exception.
@@ -285,16 +287,16 @@ reject([{value}]) *Vital.Async.Promise.reject()*
285287
<
286288
all({promises}) *Vital.Async.Promise.all()*
287289

288-
Creates a Promise object which awaits until all of {promises} has
289-
completed. It resolves the Promise object with a list of results of
290-
{promises} as following:
290+
Creates a Promise object which awaits all of {promises} has completed.
291+
It resolves the Promise object with a list of results of {promises} as
292+
following:
291293
>
292294
call Promise.all([Promise.resolve(1), Promise.resolve('foo')])
293295
\.then({arr -> execute('echo arr', '')})
294296
" It shows [1, 'foo']
295297
<
296-
If one of them is rejected, it does not await for other
297-
Promise objects and the Promise object is rejected immediately.
298+
If one of them is rejected, it does not await other Promise objects
299+
and the Promise object is rejected immediately.
298300

299301
>
300302
call Promise.all([Promise.resolve(1), Promise.reject('ERROR!')])
@@ -404,8 +406,8 @@ asynchronous operation. It represents one of following states:
404406

405407
{promise}.catch([{onRejected}]) *Vital.Async.Promise-Promise.catch()*
406408

407-
It is a shortcut function of calling .then() where first argument is
408-
|v:null|.
409+
It is a shortcut function of calling .then() where the first argument
410+
is |v:null|.
409411
>
410412
" Followings are equal
411413
call Promise.reject('ERROR').then(v:null, {msg -> execute('echo msg', '')})
@@ -416,7 +418,7 @@ Exception Object *Vital.Async.Promise-objects-Exception*
416418

417419
Exception object represents an exception of Vim script. Since Vim script's
418420
|v:exception| is a |String| value and a stack trace of the exception is
419-
separated to |v:throwpoint| variable, it does not fit to Promise API.
421+
separated to |v:throwpoint| variable, it does not fit Promise API.
420422
So we need to define our own exception object. It is passed to {onRejected}
421423
parameter of .then() or .catch() method.
422424

@@ -433,8 +435,8 @@ Example:
433435
" {'exception': 'Vim(return):E691: ...', 'throwpoint': '...'}
434436
<
435437
Exception object has two fields; "exception" and "throwpoint".
436-
"exception" is a error message. It's corresponding to |v:exception|. And
437-
"throwpoint" is a stack trace of caught exception. It's corresponding to
438+
"exception" is an error message. It's corresponding to |v:exception|. And
439+
"throwpoint" is a stack trace of the caught exception. It's corresponding to
438440
|v:throwpoint|.
439441

440442
==============================================================================

0 commit comments

Comments
 (0)