/**
* basic usage of bluebird
*/
var Promise = require("bluebird");
//defining an async function
var clAsync = function () {
var P = new Promise(function (resolve, reject) {
console.log('Write from function');
resolve('ok');
reject('not ok');
});
/*
{
"isFulfilled": true,
"isRejected": false,
"fulfillmentValue": "ok"
}
*/
console.log(JSON.stringify(P, null, 2));
return P;
};
console.log(JSON.stringify(clAsync, null, 2)); //undefined
//executing promisified function clAsync() and adding new callback with then method
clAsync()
.then(function (returnedVal) {
console.log('THEN 1 - fulfillmentValue= ' + returnedVal);
return {one: 1, two: 'drugi'}; //returning to next then
})
.then(function (returnedVal) {
console.logs('THEN 2 - fulfillmentValue= ' + returnedVal.one + returnedVal.two);
// return new Error('Namjerna greška'); --doesn't work
throw new Error('Namjerna greška', 'someFile.js', 152);
})
//catch type errors
.catch(TypeError, function (e) {
console.error(e.stack);
// console.error(e.message);
})
//catch all other errors
.catch(function (e) {
console.error(e.message);
// console.error(e.stack);
});
$ps -aux | grep node (list all node processes) sasa 1197 1.1 0.6 1327212 101308 ? Ssl Oct18 432:47 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1211 6.9 0.7 11845376 125188 ? Ssl Oct18 2509:33 node /home/sasa/dex8/dex8-api/starter.js sasa 1218 0.4 0.5 11799728 82384 ? Ssl Oct18 163:26 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1219 0.8 0.6 11815456 106092 ? Ssl Oct18 291:42 node /home/sasa/dex8/dex8-www/server/index.js sasa 1232 0.4 0.5 11800252 85160 ? Ssl Oct18 170:39 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1248 0.6 0.5 1332152 82940 ? Ssl Oct18 235:23 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1274 0.3 0.4 1310052 76500 ? Ssl Oct18 114:50 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1277 0.3 0.3 1297376 63372 ? Ssl Oct18 113:06 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1337 0.7 0.7 1166748 118348 ? Ssl Oct18 255:52 node /home/sasa/voovuu/voovuu-api/starter.js sasa 1385 4.1 3.9 12343336 644268 ? Ssl Oct18 1510:07 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1387 0.3 0.4 11797708 81496 ? Ssl Oct18 126:49 node /home/sasa/@mikosoft/dodo-examples/server/index.js sasa 1457 0.3 0.3 1099360 61176 ? Ssl Oct18 115:08 node /home/sasa/dex8/dex8-worker/starter.js sasa 1458 0.3 0.4 22279084 77756 ? Ssl Oct18 117:34 node /home/sasa/dex8/dex8-worker/starter.js sasa 1514 0.3 0.3 1100260 62700 ? Ssl Oct18 114:42 node /home/sasa/dex8/dex8-worker/starter.js sasa 1515 0.3 0.3 1099620 62252 ? Ssl Oct18 114:23 node /home/sasa/dex8/dex8-worker/starter.js sasa 1593 0.3 0.3 1099616 62836 ? Ssl Oct18 115:01 node /home/sasa/dex8/dex8-worker/starter.js sasa 1595 0.3 0.3 1099872 63380 ? Ssl Oct18 114:43 node /home/sasa/dex8/dex8-worker/starter.js sasa 1660 0.3 0.3 1099248 62080 ? Ssl Oct18 114:27 node /home/sasa/dex8/dex8-worker/starter.js sasa 1661 0.3 0.3 1099872 62884 ? Ssl Oct18 114:32 node /home/sasa/dex8/dex8-worker/starter.js sasa 1732 0.3 0.3 1099104 61908 ? Ssl Oct18 114:38 node /home/sasa/dex8/dex8-worker/starter.js sasa 1734 0.3 0.3 1099872 63060 ? Ssl Oct18 114:13 node /home/sasa/dex8/dex8-worker/starter.js sasa 1792 2.6 3.9 12346460 641432 ? Ssl Oct18 955:02 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. sasa 367471 1.1 1.0 11874648 175176 ? Ssl Oct21 357:33 node /home/sasa/miko/miko-hr/server/index.js sasa 2446447 0.4 0.6 11853564 112720 ? Ssl Nov09 19:45 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 2511306 0.5 0.5 1329612 84520 ? Ssl Nov10 18:00 node /home/sasa/miko/miko-hr/api/starter.js www-data 2747018 0.0 0.0 2608 532 ? S 16:12 0:00 sh -c ps -aux | grep node www-data 2747020 0.0 0.0 3304 648 ? S 16:12 0:00 grep node