There's setTimeout, and there is also digitalPulse which can be used to send carefully timed pulses.
An actual delay function isn't implemented because it encourages you to write code that causes problems for Espruino. As Espruino doesn't have preemptive multitasking, other tasks cannot execute until the current task has finished. If you make your current task take a long time to execute then it will probably cause problems for other tasks - if serial data or pin changes can't be processed in a sensible time period, the input buffers might overflow and data will be lost.
You can still delay your code quite easily (var t=getTime()+1000;while(getTime()<t);), but you should seriously consider re-writing your code to use setTimeout and/or digitalPulse - the end result will be a much faster, more efficient piece of code.
If you tell us what you want to do, we can maybe suggest a way of doing it?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
There's setTimeout, and there is also digitalPulse which can be used to send carefully timed pulses.
An actual delay function isn't implemented because it encourages you to write code that causes problems for Espruino. As Espruino doesn't have preemptive multitasking, other tasks cannot execute until the current task has finished. If you make your current task take a long time to execute then it will probably cause problems for other tasks - if serial data or pin changes can't be processed in a sensible time period, the input buffers might overflow and data will be lost.
You can still delay your code quite easily (
var t=getTime()+1000;while(getTime()<t);
), but you should seriously consider re-writing your code to use setTimeout and/or digitalPulse - the end result will be a much faster, more efficient piece of code.If you tell us what you want to do, we can maybe suggest a way of doing it?