Skip to main content

Posts

Showing posts with the label promise

Learn about promise and q in node js

Good Link to study promises in node https://www.youtube.com/watch?v=s6SH72uAn3Q Use-cases of promises and reasons to switch to promises https://spion.github.io/posts/why-i-am-switching-to-promises.html Sample program with q and promises  const {PythonShell} =  require('python-shell'); var Q = require('q'); var Promise = require('promise'); var pk = function runPythonShell(){ return  Q.Promise(function(resolve, reject){ PythonShell.runString('x=1+1;print(x)', null, function(err , result){ if(err){ reject(err); }else{         console.log("result " + result); resolve("finshed"); } }) }); } Q.fcall(pk) .then(function (value4) {     // Do something with value4     console.log("lola next"); }) .catch(function (error) {     // Handle any error from all above steps     console.log("there is some error");     console.log(error); }) .done();