在Raspberry PI的NodeJS中设置setTimeout
我有一个奇怪的问题,在树莓派上,long setTimeouts不会触发,但是它们在Ubuntu / x64和OSX上。
'use strict'; const delay = 1000 * 3600 * 8; const date = new Date(); date.setTime(new Date().getTime() + delay); console.log('Alarm set to', date.toString()); setTimeout(function () { console.log('Alarm!', new Date()); }, delay);
这段代码会回显Alarm!
在Ubuntu / x64上8小时之后,但从来没有在RPI上触发。
作品:
- Ubuntu的/ 64
- OSX
不起作用:
- RPI b +与Raspian 7(节点6.1)
- 带Raspian 8的RPI 3(节点4.4.4,6.0和6.1)
根据ps
脚本处于Sl
状态:可Interruptible sleep (waiting for an event to complete), is multi-threaded (using CLONE_THREAD, like NPTL pthreads do).
在这个代码的更复杂的版本中,我可以通过Web UI控制脚本,在设置的时间之后,“警报”将会closures,但只有当我访问Web UI(唤醒应用程序?)时才会停止。
这是一个NodeJS的错误,或者我做了些什么东西?
添加这个解决了它,直到NodeJS问题得到解决。
// Every 20 min to keep awake setInterval(() => 1, 1000 * 60 * 20);