/**
* 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.4 0.4 1302468 78440 ? Ssl Oct24 29:42 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1200 0.7 0.8 11717872 133920 ? Ssl Oct24 51:40 node /home/sasa/dex8/dex8-api/starter.js sasa 1207 0.3 0.4 1301220 67932 ? Ssl Oct24 22:21 node /home/sasa/regoch/regoch-www/server sasa 1208 0.3 0.3 1299336 65336 ? Ssl Oct24 21:15 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1224 0.7 0.6 11815204 98808 ? Ssl Oct24 50:05 node /home/sasa/dex8/dex8-www/server/index.js sasa 1236 0.3 0.5 11810060 96556 ? Ssl Oct24 26:47 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1255 0.5 0.4 1328700 81536 ? Ssl Oct24 40:10 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1257 0.3 0.4 1300872 67612 ? Ssl Oct24 21:47 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1289 0.3 0.3 1296500 64020 ? Ssl Oct24 21:10 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1292 0.4 0.5 11817136 89300 ? Ssl Oct24 28:53 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 1361 0.6 0.6 1154044 109520 ? Ssl Oct24 45:12 node /home/sasa/voovuu/voovuu-api/starter.js sasa 1363 2.0 2.0 12106168 339464 ? Ssl Oct24 137:02 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1441 0.3 0.4 11794184 77656 ? Ssl Oct24 22:55 node /home/sasa/@mikosoft/dodo-examples/server/index.js sasa 1449 0.3 0.3 1165032 63716 ? Ssl Oct24 22:08 node /home/sasa/dex8/dex8-worker/starter.js sasa 1528 1.3 0.8 22333172 136392 ? Ssl Oct24 92:18 node /home/sasa/dex8/dex8-worker/starter.js sasa 1529 0.3 0.4 1102948 67216 ? Ssl Oct24 22:04 node /home/sasa/dex8/dex8-worker/starter.js sasa 1606 0.3 0.4 1102948 67224 ? Ssl Oct24 22:16 node /home/sasa/dex8/dex8-worker/starter.js sasa 1607 0.3 0.4 1102948 66752 ? Ssl Oct24 22:07 node /home/sasa/dex8/dex8-worker/starter.js sasa 1705 0.3 0.4 1102952 68700 ? Ssl Oct24 22:06 node /home/sasa/dex8/dex8-worker/starter.js sasa 1706 0.3 0.4 1102948 66932 ? Ssl Oct24 22:05 node /home/sasa/dex8/dex8-worker/starter.js sasa 1805 0.3 0.4 1102944 67496 ? Ssl Oct24 22:05 node /home/sasa/dex8/dex8-worker/starter.js sasa 1807 0.3 0.3 1099872 63576 ? Ssl Oct24 21:52 node /home/sasa/dex8/dex8-worker/starter.js sasa 1885 0.3 0.3 1099368 63800 ? Ssl Oct24 21:52 node /home/sasa/dex8/dex8-worker/starter.js sasa 1886 0.7 0.6 11815940 113976 ? Ssl Oct24 50:06 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. www-data 1030989 0.0 0.0 2608 592 ? S 08:23 0:00 sh -c ps -aux | grep node www-data 1030991 0.0 0.0 3304 716 ? S 08:23 0:00 grep node