-
Notifications
You must be signed in to change notification settings - Fork 0
Memoization
Logan Savage edited this page May 27, 2026
·
2 revisions
If doing operations in a loop, the library provides a Memoize() action that will pull down the device list and cache it after running all filters. This will prevent recalculating the device list every iteration of the loop.
allLights := controller.Devices().
TypeIs(veego.DeviceLight).
Memoize()
err = allLights.On().Exec()
if err != nil {
log.Fatal(err)
}
// Turn up the brightness from 0% to 100% in increments of 5%
for i := 0; i <= 100; i += 5 {
err := allLights.
Brightness(veego.Percentage(i)).
Exec()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Lamps at %d%%\n", i)
time.Sleep(1 * time.Second)
}Unlike other actions, additional filters could be applied to the query after memoizing it.