Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
31d0ec7e
Commit
31d0ec7e
authored
Apr 10, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweak docs on lazy promise evaluation.
parent
382d9930
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
8 deletions
+16
-8
cxxrpc.md
doc/cxxrpc.md
+16
-8
No files found.
doc/cxxrpc.md
View file @
31d0ec7e
...
...
@@ -157,14 +157,22 @@ called when the promise either completes or is canceled.
### Lazy Execution
Callbacks registered with
`.then()`
which aren't themselves asynchronous (i.e. they return a value,
not a promise) won't be executed by default. There are several ways to force a promise to execute
eagerly:
*
`.wait()`
on it.
*
`.detach()`
it.
*
Add it to a
`kj::TaskSet`
(this is a lot like
`detach()`
, except that you can cancel all tasks in
the set by destroying the set).
*
Call
`.eagerlyEvaluate()`
on it.
not a promise) by default won't execute unless the result is actually used -- they are executed
"lazily". This allows the runtime to optimize by combining a series of .then() callbacks into one.
To force a
`.then()`
callback to execute as soon as its input is available, do one of the
following:
*
Add it to a
`kj::TaskSet`
-- this is usually the best choice. You can cancel all tasks in the set
by destroying the
`TaskSet`
.
*
`.wait()`
on it -- but this only works in a top-level wait scope, typically your program's main
function.
*
Call
`.eagerlyEvaluate()`
on it. This returns a new
`Promise`
. You can cancel the task by
destroying this
`Promise`
(without otherwise consuming it).
*
`.detach()`
it.
**WARNING:**
`.detach()`
is dangerous because there is no way to cancel a promise
once it has been detached. This can make it impossible to safely tear down the execution
environment, e.g. if the callback has captured references to other objects. It is therefore
recommended to avoid
`.detach()`
except in carefully-controlled circumstances.
### Other Features
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment