最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

在自己的回调中调用一个函数

IT培训 admin 4浏览 0评论

在自己的回调中调用一个函数

我的NodeJS应用程序运行我的C ++应用程序并观察它。如果应用程序被杀死,服务器将再次运行它。如果我的应用程序运行了几天,如果假设这个kill / die场景发生了太多次,它会导致堆栈溢出吗?如果是,请您提供解决方案吗?

谢谢

import { execFile } from "child_process";

function runRedirector(){
    execFile("./redirector.out", ["1"], {}, function(error, stdout, stderr) {
    runRedirector();
    });
}
回答如下:

由于execFile的异步性质,你调用堆栈不会增长。当调用回调时,外部调用已经从调用堆中跳出

const {execFile} = require("child_process");

let i = 0
function runRedirector(){
    execFile("./redirector.out", ["1"], {}, function(error, stdout, stderr) {
      console.log('In callback', i++)
      runRedirector();
    });
    console.log('In runDirector', i);  // this will be logged first
}

在自己的回调中调用一个函数

我的NodeJS应用程序运行我的C ++应用程序并观察它。如果应用程序被杀死,服务器将再次运行它。如果我的应用程序运行了几天,如果假设这个kill / die场景发生了太多次,它会导致堆栈溢出吗?如果是,请您提供解决方案吗?

谢谢

import { execFile } from "child_process";

function runRedirector(){
    execFile("./redirector.out", ["1"], {}, function(error, stdout, stderr) {
    runRedirector();
    });
}
回答如下:

由于execFile的异步性质,你调用堆栈不会增长。当调用回调时,外部调用已经从调用堆中跳出

const {execFile} = require("child_process");

let i = 0
function runRedirector(){
    execFile("./redirector.out", ["1"], {}, function(error, stdout, stderr) {
      console.log('In callback', i++)
      runRedirector();
    });
    console.log('In runDirector', i);  // this will be logged first
}

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论