Reputation: 115
I have a problem with accessing multiple controller at the same time, example I'm accessing the method "access" while "access" is active, I can't use/access the method "other" or other controllers in the client side, but when the looping in "access" is done, I can use other methods or controllers, is SailsJs controller Single Threading?
access: function (req, res) {
// Assume that I'll generate 1k data and I dont have problem about that
// my problem is while generating 1k data i cant access my other Controller/Method
// any solution about my problem thanks :)
// NOTE** this is just a example of the flow of my program
// In creating data Im using Async
while(x <= 1000) {
Model.create(etc, function (err, ok) {
if(err) console.log(err)
});
x++;
}
res.view('view/sampleview');
},
other: function (req, res) {
res.view('view/view');
},
Upvotes: 3
Views: 444
Reputation: 681
All controllers and actions are avaible in sails.contollers variavel Mike sails.controllers.mycontroller.access (req, res);
run in parallel, all at same time:
access: function (req, res) {
var createFunctions = [];
while(x <= 1000) {
createFunctions.push(function(done) {
Model.create(etc).exec(function (err, ok) {
if(err) return done(err); // err
done(); //success
});
})
x++;
}
async.parallel( createFunctions, function afterAll(err) {
sails.controllers.mycontroller.other (req, res);
//res.view('view/sampleview');
});
},
other: function (req, res) {
res.view('view/view');
},
run in series, one by one:
access: function (req, res) {
var createFunctions = [];
while(x <= 1000) {
createFunctions.push(function(done) {
Model.create(etc).exec(function (err, ok) {
if(err) return done(err); // err
done(); //success
});
})
x++;
}
// run in series, one by one
async.series( createFunctions, function afterAll(err) {
sails.controllers.mycontroller.other (req, res);
//res.view('view/sampleview');
});
},
other: function (req, res) {
res.view('view/view');
},
Upvotes: 2