/**
* 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.5 1304644 82340 ? Ssl Oct24 532:02 node /home/sasa/.pm2/modules/pm2-logrotate/node_modules/pm2-logr sasa 1200 0.9 0.8 11722864 139000 ? Ssl Oct24 926:07 node /home/sasa/dex8/dex8-api/starter.js sasa 1208 0.4 0.4 1305000 73820 ? Ssl Oct24 384:04 node /home/sasa/dex8/dex8-panel/server/index.js sasa 1224 0.9 0.7 11835532 115788 ? Ssl Oct24 899:12 node /home/sasa/dex8/dex8-www/server/index.js sasa 1236 0.6 0.6 11809548 99080 ? Ssl Oct24 605:05 node /home/sasa/mikosoft_hr/www-mikosoft-hr/server/index.js sasa 1255 0.8 0.5 1330860 84620 ? Ssl Oct24 824:44 node /home/sasa/mikosoft-info/api-mikosoft-info/starter.js sasa 1257 0.4 0.4 1304920 73676 ? Ssl Oct24 391:07 node /home/sasa/mikosoft-info/www-mikosoft-info/server/index.js sasa 1289 0.4 0.4 1297964 66868 ? Ssl Oct24 383:41 node /home/sasa/dex8/dex8-kiosk/server/index.js sasa 1363 4.0 2.9 12199492 480132 ? Ssl Oct24 3819:02 node /home/sasa/voovuu/voovuu-pub/server/index.js sasa 1449 0.4 0.3 1232104 65092 ? Ssl Oct24 403:37 node /home/sasa/dex8/dex8-worker/starter.js sasa 1529 0.4 0.3 1100900 64924 ? Ssl Oct24 403:09 node /home/sasa/dex8/dex8-worker/starter.js sasa 1606 0.4 0.3 1100900 64996 ? Ssl Oct24 404:05 node /home/sasa/dex8/dex8-worker/starter.js sasa 1607 0.4 0.3 1101156 64988 ? Ssl Oct24 402:49 node /home/sasa/dex8/dex8-worker/starter.js sasa 1705 0.4 0.4 1101928 66824 ? Ssl Oct24 402:17 node /home/sasa/dex8/dex8-worker/starter.js sasa 1706 0.4 0.3 1101412 65144 ? Ssl Oct24 401:38 node /home/sasa/dex8/dex8-worker/starter.js sasa 1805 0.4 0.4 1167968 66688 ? Ssl Oct24 402:53 node /home/sasa/dex8/dex8-worker/starter.js sasa 1807 0.4 0.3 1100896 64412 ? Ssl Oct24 393:34 node /home/sasa/dex8/dex8-worker/starter.js sasa 1885 0.4 0.3 1100136 64384 ? Ssl Oct24 395:26 node /home/sasa/dex8/dex8-worker/starter.js sasa 1886 2.5 1.1 11877568 180572 ? Ssl Oct24 2392:57 node /home/sasa/mikosoft-info/crypto-mikosoft-info/server/index. sasa 1136462 0.3 0.3 1100124 64624 ? Ssl 03:02 1:12 node /home/sasa/dex8/dex8-worker/starter.js www-data 1162773 0.0 0.0 2608 592 ? S 09:06 0:00 sh -c ps -aux | grep node www-data 1162775 0.0 0.0 3304 716 ? S 09:06 0:00 grep node sasa 2628167 0.9 0.7 1174632 130104 ? Ssl Nov04 766:05 node /home/sasa/voovuu/voovuu-api/starter.js sasa 3168557 0.7 0.6 11823816 111472 ? Ssl Nov06 553:12 node /home/sasa/mikosoft-info/dodo-mikosoft-info/server/index.js sasa 3169051 0.5 0.5 11798920 84104 ? Ssl Nov06 387:57 node /home/sasa/@mikosoft/dodo-examples/server/index.js