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