Delay
Available Functions
samples(signal, delay, initial)
Delay a signal by some amount of “samples”
Usage
core.delay.samples(signal, delay);
core.delay.samples(signal, delay, initial);
Arguments
- signal
- [any] raw value
- delay
- [number] number of samples to delay the output
- initial
- [any] (optional) value to use for the first
delayseconds (defaults to first received value)
time(signal, delay, initial)
Delay a signal by some amount of time
Usage
core.delay.time(signal, delay);
core.delay.time(signal, delay, initial);
Arguments
- signal
- [any] raw value
- delay
- [number] time, in seconds, to delay the output
- initial
- [any] (optional) value to use for the first
delayseconds (defaults to first received value)
timeToTrue(signal, delay)
Delay the rising edge of a signal for delay seconds. Falling edges are passed through without delay. The output takes the value of the input after delay seconds from the last rising edge. So if the input is false at delay seconds, the output stays false.
Usage
core.delay.timeToTrue(signal, delay);
Arguments
- signal
- [boolean] raw value
- delay
- [number] time, in seconds, to delay the output rising edge
timeToFalse(signal, delay)
Delay the falling edge of a signal for delay seconds. Rising edges are passed through without delay. The output takes the value of the input after delay seconds from the last rising edge. So if the input is true at delay seconds, the output stays true.
Usage
core.delay.timeToFalse(signal, delay);
Arguments
- signal
- [boolean] raw value
- delay
- [number] time, in seconds, to delay the output falling edge
NOTE: Delaying objects and arrays
samples and time store the signal (and initial) value in their delay buffer by reference, and time returns a reference to a value that may still be in the buffer. When the signal is a primitive (number, string, boolean) this has no effect. When it is an object or array, changing it in your script after calling the function also changes the delayed values held in the buffer:
- Modifying the object/array you passed in as the signal (e.g.
signal.value = 0orsignal.push(x)) alters the value that will be returned later. - Modifying the object/array returned by
timealters the buffered value, so it may be seen again on a later evaluation. - With
samples, the same initial (or first-received) object fills every slot of the buffer, so modifying one delayed value modifies all of them.
To avoid this, pass a copy of the value (e.g. JSON.parse(JSON.stringify(signal))) and copy the result before changing it. timeToTrue and timeToFalse only accept boolean signals and are not affected.