根据文件 https://nodered.org/docs/creating-nodes/node-js 当Node-red(或所讨论的特定节点)关闭时,"关闭"调用event,如果一个监听器注册了参数,它应该在完全停止之前等待done()。
this.on('close', function(done) {
doSomethingWithACallback(function() {
done();
});
});
但是,它并不适合我。我的错,我确定,但我不知道在哪里。以下代码显示第一个" Closing"在日志中输入,但不是第二个条目"等待足够。实际上现在正在完成。":
node.on("close", function(done) {
node.log('Closing.');
setTimeout(function(){
node.log('Waited enough.Actually finishing now.');
done();
},5000);
});
有人可以给我一个指针吗?
使用: 节点红色0.17.5 node.js 6.14.1
编辑:添加输出日志
pi@raspberrypi:~ $ node-red-start
Start Node-RED
Once Node-RED has started, point a browser at http://192.168.1.17:1880
On Pi Node-RED works better with the Firefox or Chrome browser
Use node-red-stop to stop Node-RED
Use node-red-start to start Node-RED again
Use node-red-log to view the recent log output
Use sudo systemctl enable nodered.service to autostart Node-RED at every boot
Use sudo systemctl disable nodered.service to disable autostart on boot
To find more nodes and example flows - go to http://flows.nodered.org
Starting as a systemd service.
Started Node-RED graphical event wiring tool..
16 Apr 10:11:27 - [info]
Welcome to Node-RED
===================
16 Apr 10:11:27 - [info] Node-RED version: v0.17.5
16 Apr 10:11:27 - [info] Node.js version: v6.14.1
16 Apr 10:11:27 - [info] Linux 4.14.30-v7+ arm LE
16 Apr 10:11:30 - [info] Loading palette nodes
16 Apr 10:11:47 - [info] Dashboard version 2.7.0 started at /ui
16 Apr 10:11:50 - [info] Settings file : /home/pi/.node-red/settings.js
16 Apr 10:11:50 - [info] User directory : /home/pi/.node-red
16 Apr 10:11:50 - [info] Flows file : /home/pi/.node-red/flows_raspberrypi.json
16 Apr 10:11:50 - [info] Server now running at http://127.0.0.1:1880/
16 Apr 10:11:51 - [info] Starting flows
16 Apr 10:11:51 - [info] Started flows
Stopping Node-RED graphical event wiring tool....
16 Apr 10:12:06 - [info] Stopping flows
16 Apr 10:12:06 - [info] [simple-queue:queue1] Closing.
Stopped Node-RED graphical event wiring tool..
答案 0 :(得分:1)
您正在尝试在Node-RED 0.18中修复的错误。
在Node-RED 0.18之前,处理运行时关闭的代码没有等待所有节点关闭处理程序在进程终止之前完成。