You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update code for require("timer").add({type:"EXEC",fn:...}) to look up the function that is being called. It's much safer than storing the reference directly as defrags could have moved the function
// eg. execute myFunction in 100ms, then 200ms thereafter
215
220
require("timer").add({
216
-
type:"EXEC", fn:myFunction,
221
+
type:"EXEC", fn: () => LED.toggle(),
217
222
time:100,
218
223
interval:200,
219
224
});
220
225
```
226
+
227
+
**Note:** `require("timer").add({type:"EXEC",fn:...})` differs from `setInterval`/`setTimeout` in that
228
+
it is scheduled using a hardware timer. When the timer fires, JavaScript that's executing will be
229
+
paused at the next statement and the JS will be executed right away. This can be great for things
230
+
like scanning out screens where you don't want your execution to be paused even if you're executing
231
+
JavaScript code.
221
232
*/
222
233
intjswrap_timer_add(JsVar*timer) {
223
234
JsVarFloattime=0, interval=0;
@@ -265,13 +276,11 @@ int jswrap_timer_add(JsVar *timer) {
265
276
task->data.set.value=value;
266
277
} elseif (evtType==UET_EXECUTE) {
267
278
if (jsvIsFunction(fn)) { // if a function is passed we use EXEC_RUN_INTERRUPT_JS
268
-
if (jsvGetRefs(fn) ==0) {
269
-
jsExceptionHere(JSET_ERROR, "Function passed to timer must be referenced elsewhere");
270
-
jsvUnLock(fn);
271
-
return-1;
272
-
}
279
+
JsVar*timerFns=jsvObjectGetChild(execInfo.hiddenRoot, JSI_TIMER_RUN_JS_NAME, JSV_ARRAY); // set the timer function in the hidden scope so we can look it up later
0 commit comments