Skip to content

Await

Name Mandatory Description Default Type
⬅️ Input Must match the input types of the first shard in the sequence. Any
Output ➡️ Will match the output types of the first shard of the sequence. Any
Shards No The shards to activate. none Shard[Shard]None

Executes a shard or a sequence of shards asynchronously and awaits their completion.

Details

(Await) runs its shards (or sequence of shards) as a separate task that is sent directly to the thread pool, while the rest of the program continues executing (via other scheduled threads). Once this (Await) task thread completes its execution the result of the execution of these inner shards is made available to the program.

This is called asynchronous computation and is used to prevent resource intensive processing (like downloading a large file data from an http server) from holding up the execution of the rest of the program.

Note

(Await) has an alias (||) which is more convenient to use. || also removes the need to use (->) as, unlike (Await), it doesn't require the parameter shards to be grouped together.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
; Asynchronous execution of shards (using keyword `Await`)
; Printing order of messages not consistent across program runs --
; -- as asynchronous shards might complete at different times
@wire(await-wire {
  Await({
    {Msg("Message 1")}
    ; messages might print in any order (1/2/3, 1/3/2, 3/2/1, etc.)
    {Msg("Message 2")}
    ; messages might print in any order (1/2/3, 1/3/2, 3/2/1, etc.)
  })
})

@wire(my-wire {
  {Msg("Message 3")}
  ; messages might print in any order (1/2/3, 1/3/2, 3/2/1, etc.)
})

Do(await-wire)
Do(my-wire)

[info] [await-wire] Message 1
[info] [await-wire] Message 2
[info] [my-wire] Message 3