Skip to content

Once

Name Mandatory Description Default Type
⬅️ Input The input of the shard, if any Any
Output ➡️ The resulting output of the shard Any
Action No The shard or sequence of shards to execute. none Shard[Shard]
Every No The number of seconds to wait until repeating the action, if 0 the action will happen only once per wire flow execution. none FloatVar(Float)

Executes the shard or sequence of shards with the desired frequency in a wire flow execution.

Details

If you run Once with Every set to its default value (i.e., 0), the sequence of shards will be executed only once per wire flow execution.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
; Once
@wire(test1 {
  "Hello World, every 1.5s during a wire flow execution" = string1
  "Hello World, once during every wire flow execution" = string2

  string1 | Once({
    Log
  } Every: 1.5) ; string logs once every 1.5 secs i.e for a total of 3 times

  string2 | Once({
    Log
  }) ; Every defaults to 0 so this string logs only once
})

; here one wire flow execution is 5 secs (5 mesh iterations, one per second)
; so string1 logs for a maximum of 5/(1.5) => ~3 times and string2 logs only once
{Do(test1)}
{Do(test1)}
{Do(test1)}
{Do(test1)}
{Do(test1)}

; Setup
@wire(test2 {
  Once({
    0 >= counter
    counter | Log("counter set to 0 only once")
    ; => 0
  })

  Math.Inc(counter)
  counter | Log("counter incremented every time wire executes")
  ; => 1, 2, 3, 4, 5
})

{Do(test2)}
{Do(test2)}
{Do(test2)}
{Do(test2)}
{Do(test2)}

[info] [test1] Hello World, every 1.5s during a wire flow execution
[info] [test1] Hello World, once during every wire flow execution
[info] [test2] counter set to 0 only once: 0
[info] [test2] counter incremented every time wire executes: 1
[info] [test2] counter incremented every time wire executes: 2
[info] [test2] counter incremented every time wire executes: 3
[info] [test2] counter incremented every time wire executes: 4
[info] [test2] counter incremented every time wire executes: 5