/**
* 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 1303660 81668 ? Ssl Oct24 289:24 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1200 0.9 0.8 11722608 139772 ? Ssl Oct24 512:49 node /home/sasa/dex8/dex8-api/starter.js sasa 1207 0.4 0.4 1304908 73536 ? Ssl Oct24 240:34 node /home/sasa/regoch/regoch-www/server sasa 1208 0.3 0.4 1304912 72944 ? Ssl Oct24 207:48 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1224 0.8 0.6 11817252 103680 ? Ssl Oct24 499:00 node /home/sasa/dex8/dex8-www/server/index.js sasa 1236 0.5 0.5 11813132 98192 ? Ssl Oct24 318:43 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1255 0.7 0.5 1330860 84300 ? Ssl Oct24 429:15 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1257 0.3 0.4 1302184 71204 ? Ssl Oct24 211:17 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1289 0.3 0.4 1298156 66372 ? Ssl Oct24 208:18 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1363 3.1 2.7 12166612 444568 ? Ssl Oct24 1765:50 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1449 0.3 0.3 1166568 64416 ? Ssl Oct24 218:19 node /home/sasa/dex8/dex8-worker/starter.js sasa 1528 1.7 2.5 33081864 422896 ? Ssl Oct24 991:59 node /home/sasa/dex8/dex8-worker/starter.js sasa 1529 0.3 0.4 1103204 66240 ? Ssl Oct24 218:02 node /home/sasa/dex8/dex8-worker/starter.js sasa 1606 0.3 0.3 1100388 64592 ? Ssl Oct24 218:08 node /home/sasa/dex8/dex8-worker/starter.js sasa 1607 0.3 0.3 1100644 64720 ? Ssl Oct24 217:31 node /home/sasa/dex8/dex8-worker/starter.js sasa 1705 0.3 0.3 1101160 64960 ? Ssl Oct24 217:31 node /home/sasa/dex8/dex8-worker/starter.js sasa 1706 0.3 0.3 1101412 65332 ? Ssl Oct24 217:19 node /home/sasa/dex8/dex8-worker/starter.js sasa 1805 0.3 0.4 1167200 66308 ? Ssl Oct24 217:37 node /home/sasa/dex8/dex8-worker/starter.js sasa 1807 0.3 0.4 1102944 67232 ? Ssl Oct24 213:12 node /home/sasa/dex8/dex8-worker/starter.js sasa 1885 0.3 0.4 1102184 65756 ? Ssl Oct24 214:36 node /home/sasa/dex8/dex8-worker/starter.js sasa 1886 1.7 0.9 11857232 159852 ? Ssl Oct24 969:47 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. www-data 383526 0.0 0.0 2608 524 ? S 15:57 0:00 sh -c ps -aux | grep node www-data 383528 0.0 0.0 3304 720 ? S 15:57 0:00 grep node sasa 2628167 0.8 0.7 1173440 128436 ? Ssl Nov04 329:53 node /home/sasa/voovuu/voovuu-api/starter.js sasa 3168557 0.6 0.5 11811020 94932 ? Ssl Nov06 236:56 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 3169051 0.4 0.5 11798664 82564 ? Ssl Nov06 155:28 node /home/sasa/@mikosoft/dodo-examples/server/index.js