Pages
Introduction
Getting Started
Recipes
Reference
Literals
Arrays
Tuples
Type System
Functions
Modules
Records
Enums
Built-in Types
Constants
Equality
Stores
Routing
Comments
Control Expressions
Components
Properties
Computed Properties
Styling Elements
Connecting Stores
Using Providers
Internal State
Referencing Entities
Global Components
Lifecycle Functions
Directives
JavaScript Interop
Environment Variables
Packages
parallel
parallel
expressions allow you to do things in parallel, and then do things with
their results.
A
parallel
expression is built up from multiple parts:
-
expressions or statements that return a
Promise
or aResult
-
an optional
then
branch -
catch
branches -
an optional
finally
branch
An example:
parallel {
articles =
loadImages()
users =
loadUsers()
} then {
next {
articles = articles,
users = users,
}
} catch {
/* errors are caught here. */
} finally {
/* Clean things up here. */
}
Keep in mind that you need to handle all possible errors that can be returned from a statement, although the compiler has your back here and will show an error if you forget one.
The return value of a
parallel
expression is always a
Promise(error, result)
:
-
If the value of the
then
branch is aPromise
then it will be returned as is -
If the value of the
then
branch is not aPromise
then it will return a promise which never failsPromise(Never, result)
where theresult is the value of thethen
branch -
If there is no
then
branch then the return value isPromise(Never, Void)
A few notable things to keep in mind:
- All of the catches must match the return value of the last statement
- Results are unwrapped into variables
-
Promises are
await
-ed and unwrapped into variables