/**
* 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 1304060 80812 ? Ssl Oct24 205:12 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1200 0.9 0.8 11721656 138048 ? Ssl Oct24 358:06 node /home/sasa/dex8/dex8-api/starter.js sasa 1207 0.4 0.4 1305072 73320 ? Ssl Oct24 163:41 node /home/sasa/regoch/regoch-www/server sasa 1208 0.3 0.4 1302352 70948 ? Ssl Oct24 146:57 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1224 0.9 0.6 11825956 104612 ? Ssl Oct24 364:13 node /home/sasa/dex8/dex8-www/server/index.js sasa 1236 0.5 0.5 11813132 97744 ? Ssl Oct24 223:24 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1255 0.7 0.5 1330064 83456 ? Ssl Oct24 290:08 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1257 0.4 0.4 1300548 69788 ? Ssl Oct24 149:10 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1289 0.3 0.4 1297512 66396 ? Ssl Oct24 147:20 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1363 3.2 2.6 12162420 440508 ? Ssl Oct24 1212:00 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1449 0.4 0.3 1166312 63964 ? Ssl Oct24 154:27 node /home/sasa/dex8/dex8-worker/starter.js sasa 1528 1.8 2.5 22603208 425792 ? Ssl Oct24 670:57 node /home/sasa/dex8/dex8-worker/starter.js sasa 1529 0.4 0.4 1103204 66940 ? Ssl Oct24 154:22 node /home/sasa/dex8/dex8-worker/starter.js sasa 1606 0.4 0.3 1099364 63508 ? Ssl Oct24 154:26 node /home/sasa/dex8/dex8-worker/starter.js sasa 1607 0.4 0.3 1099876 64004 ? Ssl Oct24 153:55 node /home/sasa/dex8/dex8-worker/starter.js sasa 1705 0.4 0.3 1100392 64184 ? Ssl Oct24 153:38 node /home/sasa/dex8/dex8-worker/starter.js sasa 1706 0.4 0.3 1100132 64264 ? Ssl Oct24 153:53 node /home/sasa/dex8/dex8-worker/starter.js sasa 1805 0.4 0.3 1100640 64848 ? Ssl Oct24 153:55 node /home/sasa/dex8/dex8-worker/starter.js sasa 1807 0.4 0.3 1101664 65392 ? Ssl Oct24 150:45 node /home/sasa/dex8/dex8-worker/starter.js sasa 1885 0.4 0.3 1100648 65088 ? Ssl Oct24 151:35 node /home/sasa/dex8/dex8-worker/starter.js sasa 1886 1.4 0.9 11848088 149404 ? Ssl Oct24 556:27 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. www-data 1391333 0.0 0.0 2608 588 ? S 11:30 0:00 sh -c ps -aux | grep node www-data 1391335 0.0 0.0 3304 712 ? S 11:30 0:00 grep node sasa 2628167 0.9 0.7 1162320 117884 ? Ssl Nov04 191:31 node /home/sasa/voovuu/voovuu-api/starter.js sasa 3168557 0.6 0.5 11820728 97168 ? Ssl Nov06 125:24 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 3169051 0.4 0.5 11798408 83528 ? Ssl Nov06 84:10 node /home/sasa/@mikosoft/dodo-examples/server/index.js