gpt4 book ai didi

Javascript自动重启

转载 作者:搜寻专家 更新时间:2023-11-01 00:06:23 24 4
gpt4 key购买 nike

我有 8 个 javascript,它们是通过我的 linux 机器上的 Node 启动的。

我想要的是当脚本完成并自行关闭时,它会自动重新启动。

因此我创建了一个如下所示的 start.sh

while true; do
node 1.js & node 2.js & node 3.js & node 4.js & node 5.js & node 6.js & node 7.js & node 8.js;
done

当我通过 ./start.sh 启动它时,所有脚本都会启动,但它们不会在完成后自动重启。

有什么我可以添加到重新启动的脚本本身吗?我试过了

while(true) {
//code//
}

但这会重新启动脚本,即使它没有完成。

最佳答案

尝试使用 async :

  var async = require('async');

var onejs = require('1.js');
var twojs = require('2.js');
var threejs = require('3.js');



// a simple recursive function that gets called once all functions
//are done executing, this should go on forever
function start() {
async.parallel([
onejs,
twojs,
threejs
], function done() {
start();
});
}

// remember your scripts should call async's callback,
// i am assuming you know you know how to use asyncjs.

关于Javascript自动重启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36887142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com