Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将响应返回给调用方并继续执行其他操作_Javascript_Node.js - Fatal编程技术网

Javascript 将响应返回给调用方并继续执行其他操作

Javascript 将响应返回给调用方并继续执行其他操作,javascript,node.js,Javascript,Node.js,我有一个类似这样的api方法。 我的问题是,这在某种程度上是否可能。如果没有这一点,实际上打电话的人必须 等到 someotherFunction();完成了 exports.callback = function (req, res) { getValue() .then(function (result) { return res.send(200); }) .catch(function () { return res.send(404)

我有一个类似这样的api方法。 我的问题是,这在某种程度上是否可能。如果没有这一点,实际上打电话的人必须 等到 someotherFunction();完成了

exports.callback = function (req, res) {  
  getValue()
   .then(function (result) {
      return res.send(200);
    })
   .catch(function () {
      return res.send(404);
   });

   //do other stuff here without holding up the response
   someotherFunction();

 }; 

返回将不会转义exports.callback,因为它们位于其他函数中。。。(匿名功能)

这:

只是一个methode u调用,其中包含一个函数 正常情况下,它看起来像这样,没有函数

 getValue().then(res.send(200))
因此,返回将res.send(200)放置到getValue()。然后()

没别的了


因此exports.callback只会在someotherFunction()之后返回到他的调用;完成了

谢谢,还有什么其他方法可以完成这样的事情吗。意思是,在我返回响应后,触发其他事件?嗯,让我们看看。。。你可以用ajax调用其他函数,然后重新运行你的响应,这样你就不必等到其他函数完成了,这不是一个选项。回调首先不是由ajax调用触发的。所以客户端与回调无关。我会深入研究这个问题,无论如何,谢谢!所以你应该说,为什么发送回复然后做一些事情很重要。。。再加上你的问题,问题可能会在你认为的另一点上得到解决
 getValue().then(res.send(200))