Sails Js - concurrent access to multiple controllers

I have a problem with concurrent access to multiple controllers, For example, I access the method "access" when "access" is active, I cannot use / access the method "others" or other client side controllers, but when the loop in "access" is complete, I can use other methods or controllers, is the 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');
},

      

+3


source to share


1 answer


All controllers and actions are available in sails.contollers variavel Mike sails.controllers.mycontroller.access (req, res);

work in parallel, all at the 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');
},

      



are performed sequentially, in turn:

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');
},

      

+2


source







All Articles