Click here to Skip to main content
15,907,492 members

Comments by Member 12737957 (Top 13 by date)

Member 12737957 20-Jan-17 2:28am View    
Deleted
function asynchronousFunction1() {
return new Promise(
function (resolve, reject) {
//result can be any value we want to pass
resolve(result);
//it will be rejected if some error occurs
reject(error);
});
}

and we can call this function from anywhere like:

asynchronousFunction1()
.then(result{
//here the resul comes depends on what send through promise
})
.catch(error{
//Here i can handle the error
});

so, lets have a simple function in javascript to call multiple asynchrous functions:

function toCallAsyncFunctions(){

Promise.all([
asynchronousFunction1(),
asynchronousFunction2(),
asynchronousFunction3(),
asynchronousFunction4() // you can call further more
])
.then(([result1, result2 ,result3 ,result4]) {
//just sumup here all the results coming from all asynchronous functions
var sum = (result1+result2+result3+result4);
})
.catch(err {
console.log("error:",err);
});

}

and define all functions outside that function:

function asynchronousFunction1() {
return new Promise(
function (resolve, reject) {
resolve(result1);
reject(error);
});
}

function asynchronousFunction2() {
return new Promise(
function (resolve, reject) {
resolve(result2);
reject(error);
});
}

function asynchronousFunction3() {
return new Promise(
function (resolve, reject) {
resolve(result3);
reject(error);
});
}

function asynchronousFunction4() {
return new Promise(
function (resolve, reject) {
resolve(result4);
reject(error);
});
}
Member 12737957 19-Jan-17 12:00pm View    
I have problem with understanding async functions and promises and callbacks, thats the core... i read some articles but didnt quite understand them
Member 12737957 19-Jan-17 11:56am View    
I have problem with understanding async functions and promises and callbacks, thats the core... i read some articles but didnt quite understand them
Member 12737957 19-Jan-17 11:50am View    
I think that i did not apply good... Its overall confusing
Member 12737957 19-Jan-17 11:42am View    
That's a imposter. I put on some forum that I would pay if someone does it so that's not my mom its a fraud. Now I tried to do that by myself and I need help