Skip to content

Once

Name - Description Default Type
<input> Any
<output> Any
Action The shard or sequence of shards to execute. None Shard[Shard]
Every The number of seconds to wait until repeating the action, if 0 the action will happen only once per wire flow execution. None Float&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. Since this a very common use case (initialize loop counters, etc.) there's an alias for this - (Setup).

Basically, (Setup) is just (Once) with its :Every parameter value permanently set to 0.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
;; Once
(defmesh Main)
(defloop test
    "Hello World, every 1.5s during a wire flow execution" = .string1
    "Hello World, once during every wire flow execution" = .string2

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

    .string2
    (Once
        :Action (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
(schedule Main test)
(run Main 1 5)
[info] [test] Hello World, every 1.5s during a wire flow execution
[info] [test] Hello World, once during every wire flow execution
[info] [test] Hello World, every 1.5s during a wire flow execution
[info] [test] Hello World, every 1.5s during a wire flow execution
[info] [test] Hello World, every 1.5s during a wire flow execution

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
;; Setup
(defmesh Main)
(defloop test
    (Setup
        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
)
(schedule Main test)
(run Main 1 5)
[info] [test] counter set to 0 only once: 0
[info] [test] counter incremented every time wire executes: 1
[info] [test] counter incremented every time wire executes: 2
[info] [test] counter incremented every time wire executes: 3
[info] [test] counter incremented every time wire executes: 4
[info] [test] counter incremented every time wire executes: 5