/**
* 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 1303304 80508 ? Ssl Oct24 295:44 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1200 0.9 0.8 11724800 142372 ? Ssl Oct24 525:32 node /home/sasa/dex8/dex8-api/starter.js sasa 1207 0.4 0.4 1305420 73980 ? Ssl Oct24 246:45 node /home/sasa/regoch/regoch-www/server sasa 1208 0.3 0.4 1302004 69056 ? Ssl Oct24 212:51 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1224 0.9 0.6 11819512 109468 ? Ssl Oct24 525:07 node /home/sasa/dex8/dex8-www/server/index.js sasa 1236 0.5 0.6 11811084 98400 ? Ssl Oct24 326:04 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1255 0.7 0.5 1330860 84484 ? Ssl Oct24 440:00 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1257 0.3 0.4 1300548 68932 ? Ssl Oct24 216:02 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1289 0.3 0.4 1297580 65600 ? Ssl Oct24 212:58 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1363 3.1 2.8 12153556 462624 ? Ssl Oct24 1816:34 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1449 0.3 0.3 1167080 65256 ? Ssl Oct24 223:16 node /home/sasa/dex8/dex8-worker/starter.js sasa 1528 1.7 2.8 33151060 462412 ? Ssl Oct24 1021:26 node /home/sasa/dex8/dex8-worker/starter.js sasa 1529 0.3 0.3 1100644 64840 ? Ssl Oct24 222:56 node /home/sasa/dex8/dex8-worker/starter.js sasa 1606 0.3 0.3 1100388 64020 ? Ssl Oct24 223:01 node /home/sasa/dex8/dex8-worker/starter.js sasa 1607 0.3 0.3 1100900 64936 ? Ssl Oct24 222:24 node /home/sasa/dex8/dex8-worker/starter.js sasa 1705 0.3 0.3 1101160 65368 ? Ssl Oct24 222:27 node /home/sasa/dex8/dex8-worker/starter.js sasa 1706 0.3 0.3 1101156 65032 ? Ssl Oct24 222:12 node /home/sasa/dex8/dex8-worker/starter.js sasa 1805 0.3 0.4 1167200 66480 ? Ssl Oct24 222:32 node /home/sasa/dex8/dex8-worker/starter.js sasa 1807 0.3 0.3 1099872 63760 ? Ssl Oct24 218:01 node /home/sasa/dex8/dex8-worker/starter.js sasa 1885 0.3 0.3 1099624 63560 ? Ssl Oct24 219:26 node /home/sasa/dex8/dex8-worker/starter.js sasa 1886 1.7 0.9 11857232 160340 ? Ssl Oct24 1005:43 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. www-data 648299 0.0 0.0 2608 532 ? S 15:55 0:00 sh -c ps -aux | grep node www-data 648301 0.0 0.0 3304 652 ? S 15:55 0:00 grep node sasa 2628167 0.8 0.7 1171920 128428 ? Ssl Nov04 340:56 node /home/sasa/voovuu/voovuu-api/starter.js sasa 3168557 0.6 0.5 11801300 91356 ? Ssl Nov06 244:54 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 3169051 0.4 0.5 11798664 82960 ? Ssl Nov06 161:11 node /home/sasa/@mikosoft/dodo-examples/server/index.js