/**
* 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.4 1303020 80020 ? Ssl Oct24 271:03 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1200 0.9 0.8 11723120 138884 ? Ssl Oct24 475:37 node /home/sasa/dex8/dex8-api/starter.js sasa 1207 0.4 0.4 1304140 73052 ? Ssl Oct24 223:00 node /home/sasa/regoch/regoch-www/server sasa 1208 0.3 0.4 1304912 72552 ? Ssl Oct24 194:18 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1224 0.9 0.6 11823652 101124 ? Ssl Oct24 468:41 node /home/sasa/dex8/dex8-www/server/index.js sasa 1236 0.5 0.5 11810572 97636 ? Ssl Oct24 297:27 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1255 0.7 0.5 1330860 83812 ? Ssl Oct24 398:18 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1257 0.3 0.4 1301028 68860 ? Ssl Oct24 197:28 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1289 0.3 0.4 1297724 67628 ? Ssl Oct24 194:45 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1363 3.1 2.7 12145780 449260 ? Ssl Oct24 1657:48 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1449 0.3 0.3 1166568 65148 ? Ssl Oct24 204:06 node /home/sasa/dex8/dex8-worker/starter.js sasa 1528 1.7 2.6 33114568 441236 ? Ssl Oct24 906:29 node /home/sasa/dex8/dex8-worker/starter.js sasa 1529 0.3 0.4 1102180 66248 ? Ssl Oct24 203:56 node /home/sasa/dex8/dex8-worker/starter.js sasa 1606 0.3 0.4 1102948 66860 ? Ssl Oct24 203:59 node /home/sasa/dex8/dex8-worker/starter.js sasa 1607 0.3 0.4 1102692 66824 ? Ssl Oct24 203:23 node /home/sasa/dex8/dex8-worker/starter.js sasa 1705 0.3 0.3 1101416 64880 ? Ssl Oct24 203:19 node /home/sasa/dex8/dex8-worker/starter.js sasa 1706 0.3 0.3 1101412 65136 ? Ssl Oct24 203:15 node /home/sasa/dex8/dex8-worker/starter.js sasa 1805 0.3 0.3 1167200 65216 ? Ssl Oct24 203:28 node /home/sasa/dex8/dex8-worker/starter.js sasa 1807 0.3 0.3 1101920 65356 ? Ssl Oct24 199:20 node /home/sasa/dex8/dex8-worker/starter.js sasa 1885 0.3 0.3 1100904 64072 ? Ssl Oct24 200:41 node /home/sasa/dex8/dex8-worker/starter.js sasa 1886 1.6 0.9 11858256 160360 ? Ssl Oct24 866:42 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. sasa 2628167 0.8 0.7 1170068 126396 ? Ssl Nov04 300:02 node /home/sasa/voovuu/voovuu-api/starter.js sasa 3168557 0.6 0.5 11801036 90132 ? Ssl Nov06 213:03 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 3169051 0.4 0.5 11798408 83696 ? Ssl Nov06 139:10 node /home/sasa/@mikosoft/dodo-examples/server/index.js www-data 3725784 0.0 0.0 2608 592 ? S 15:31 0:00 sh -c ps -aux | grep node www-data 3725786 0.0 0.0 3304 648 ? S 15:31 0:00 grep node