std/time

# package time
# Run `b` now and every `d`
define Every [d: time] [b: block]
  b
  after d
    Every d
      b

Phrases

time.Every [d: time] [b: block]

Run b now and every d

Gives
—
Contexts
node, main
Kind
phrase, written in Synod
Source
time/every.synod:3
Examples
time/tick

time.Now

Simulated time since the run started

Gives
time
Contexts
node, main, check
Kind
phrase, native
Source
time/time.synod:3
Examples
time/tick

Examples

tick

Shows time.Every (a node ticks every second) and time.Now (the simulated clock, read in main and in the node)

# package main
# Shows time.Every (a node ticks every second) and time.Now (the simulated clock, read in main and in the node)
use example.com/library/time/tick
use std/lesson
use std/sim
use std/text
use std/time

define main
  set a to (sim.Spawn tick)
  after 3500ms
    lesson.Note (text.Join {"Ticks so far: ", (text.From a.tick.Ticks), ", clock: ", (text.From time.Now)})
  time.Every 2s
    lesson.Note "A main tick, every two seconds"
  sim.StopAt 5s
# package tick
use std/time

Node has
  set Ticks to 0
  set LastTick to 0s

# time.Every repeats its block; time.Now reads the simulated clock
define [n: Node] start
  time.Every 1s
    set n.Ticks to (n.Ticks plus 1)
    set n.LastTick to time.Now