{ sailsit }

Sails Js Tutorials for Beginners and Forum

Have a Question?

If you have any question you can ask below or enter what you are looking for!

Custom Promise

In sails we can write a custom promise, which can be used to convert any piece of code into promise
Below is an example of writing custom promise

function: getData() {
  return new Promise(function(resolve, reject){
      Model.find().exec(function(err, result){
          if(err) {
            reject(err);
          }
          resolve(result);
      });
  });
}

 
In the above method, reject() call will go to catch block of calling function and resolve() call will go to then block of calling function

Above method can be used to convert any piece of code in promise