Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.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
Sails.js后台处理循环,与连接无关_Sails.js - Fatal编程技术网

Sails.js后台处理循环,与连接无关

Sails.js后台处理循环,与连接无关,sails.js,Sails.js,如果您有一个进程循环,您希望在延迟后使用setTimeout(无论连接如何)连续运行,那么代码将从何处执行 看起来代码应该放在services目录中,但是循环从哪里开始呢?我在app.js中试过了,但一旦帆升起,它就不起作用了,看起来不像 简单示例 // MyFoo.js module.exports = { shouldFoo: true, doFoo: function(){ if(this.shouldFoo){ console.

如果您有一个进程循环,您希望在延迟后使用setTimeout(无论连接如何)连续运行,那么代码将从何处执行

看起来代码应该放在services目录中,但是循环从哪里开始呢?我在app.js中试过了,但一旦帆升起,它就不起作用了,看起来不像

简单示例

// MyFoo.js
module.exports = {

    shouldFoo: true,

    doFoo: function(){
        if(this.shouldFoo){
            console.log('fooing ...');
            setTimeout(foo, 1000);
        } else {
            this.shutdownFoo();
        }
    },

    shutdownFoo: function(){
        // finish up process
    }
}
那么我应该把:

var fooer = require('./api/services/MyFoo.js');
fooer.doFoo();

您可以在
config
文件夹()中使用
bootstrap.js

module.exports.bootstrap = function (cb) {
  var fooer = require('./api/services/MyFoo.js');
  fooer.doFoo();  

  // It's very important to trigger this callback method when you are finished 
  // with the bootstrap!  (otherwise your server will never lift, since it's waiting on the bootstrap)
  cb();
};