/**
* 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 1304332 83764 ? Ssl 2025 833:56 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1208 0.3 0.4 1305000 74364 ? Ssl 2025 594:27 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1224 0.8 0.7 11833488 122884 ? Ssl 2025 1331:14 node /home/sasa/dex8/dex8-www/server/index.js sasa 1236 0.5 0.6 11816872 106212 ? Ssl 2025 940:05 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1255 0.8 0.5 1331116 84964 ? Ssl 2025 1294:19 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1257 0.3 0.4 1303896 73116 ? Ssl 2025 604:17 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1289 0.3 0.4 1298584 68364 ? Ssl 2025 593:37 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1363 4.4 2.7 12140256 443172 ? Ssl 2025 7010:49 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1886 3.0 1.5 11947680 259528 ? Ssl 2025 4714:21 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. sasa 1214480 0.4 0.7 22311424 125656 ? Ssl 2025 283:37 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214483 0.3 0.3 1100544 64624 ? Ssl 2025 220:54 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214536 0.3 0.3 1100804 64900 ? Ssl 2025 220:16 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214544 0.3 0.4 1102568 66528 ? Ssl 2025 221:55 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214588 0.3 0.3 1100292 63760 ? Ssl 2025 220:42 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214617 0.3 0.4 1102976 68828 ? Ssl 2025 220:15 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214641 0.3 0.3 1099880 64080 ? Ssl 2025 217:01 node /home/sasa/dex8/dex8-worker/starter.js sasa 1214671 0.3 0.3 1099360 62836 ? Ssl 2025 216:12 node /home/sasa/dex8/dex8-worker/starter.js sasa 1215731 0.8 0.7 11709576 123712 ? Ssl 2025 540:21 node /home/sasa/dex8/dex8-api/starter.js sasa 1216489 0.3 0.4 1102840 66396 ? Ssl 2025 219:31 node /home/sasa/dex8/dex8-worker/starter.js sasa 2002956 0.3 0.3 1099100 63696 ? Ssl 03:03 2:27 node /home/sasa/dex8/dex8-worker/starter.js www-data 2055962 0.0 0.0 2608 592 ? S 15:16 0:00 sh -c ps -aux | grep node www-data 2055964 0.0 0.0 3304 724 ? S 15:16 0:00 grep node sasa 2628167 0.9 0.7 1177412 129864 ? Ssl 2025 1288:31 node /home/sasa/voovuu/voovuu-api/starter.js sasa 3168557 0.6 0.6 11823592 99108 ? Ssl 2025 916:27 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 3169051 0.5 0.5 11798920 84584 ? Ssl 2025 722:37 node /home/sasa/@mikosoft/dodo-examples/server/index.js