/**
* 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 1194 0.5 0.5 1305316 83740 ? Ssl 2025 605:28 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1208 0.3 0.4 1305000 73960 ? Ssl 2025 438:54 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1224 0.9 0.7 11838856 128596 ? Ssl 2025 1014:09 node /home/sasa/dex8/dex8-www/server/index.js sasa 1236 0.6 0.6 11816940 99204 ? Ssl 2025 691:42 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1255 0.8 0.5 1331116 84592 ? Ssl 2025 946:54 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1257 0.4 0.4 1303640 72536 ? Ssl 2025 446:40 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1289 0.3 0.4 1298080 66616 ? Ssl 2025 438:11 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1363 4.1 3.1 12196420 509844 ? Ssl 2025 4597:50 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1886 2.6 1.2 11894740 201024 ? Ssl 2025 2952:01 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. sasa 1214480 0.3 0.3 1099912 65424 ? Ssl 2025 55:28 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214483 0.3 0.3 1100032 64756 ? Ssl 2025 55:38 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214536 0.3 0.3 1100036 65496 ? Ssl 2025 55:22 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214544 0.3 0.4 1100008 65784 ? Ssl 2025 55:51 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214588 0.3 0.3 1100292 65492 ? Ssl 2025 55:29 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214617 0.3 0.4 1100160 65912 ? Ssl 2025 55:21 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214641 0.3 0.3 1099368 64292 ? Ssl 2025 54:30 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214671 0.3 0.3 1099104 63068 ? Ssl 2025 54:20 node /home/sasa/dex8/dex8-worker/starter.js sasa 1215731 0.5 0.7 11703544 117852 ? Ssl 2025 88:17 node /home/sasa/dex8/dex8-api/starter.js sasa 1216489 0.3 0.3 1099512 65252 ? Ssl 2025 55:12 node /home/sasa/dex8/dex8-worker/starter.js sasa 2439145 0.5 0.3 1095520 59976 ? Ssl 03:03 0:01 node /home/sasa/dex8/dex8-worker/starter.js www-data 2439495 0.0 0.0 2608 596 ? S 03:07 0:00 sh -c ps -aux | grep node www-data 2439497 0.0 0.0 3304 712 ? S 03:07 0:00 grep node sasa 2628167 0.9 0.8 1176208 133120 ? Ssl 2025 899:20 node /home/sasa/voovuu/voovuu-api/starter.js sasa 3168557 0.7 0.6 11815508 99408 ? Ssl 2025 647:45 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 3169051 0.5 0.5 11798920 84388 ? Ssl 2025 473:23 node /home/sasa/@mikosoft/dodo-examples/server/index.js