const studentRol=new Promise((resolve, reject) => {
setTimeout(()=>{
/**this function will give the value Of tageted studebt Roll number */
let RollOffStd=[1,2,3,4,5,6,7,8];
for (let index = RollOffStd[RollOffStd.length-1]+1 ; index <50; index++) {
RollOffStd.push(index)
}
resolve( RollOffStd)
reject('My name is Noor mohammad ')
},1000)
})
const mybiodata=(gRollOfStudent /* this is First parameter OF ( mybiodata function ) and You can change parameter value */)=>{
return new Promise((resolve, reject) => {
setTimeout((x) => {
let bio={
myname : 'Noor mohammad Patwary ' ,
age : 25 ,
}
resolve(`my name is ${bio.myname } and my age = ${bio.age } and my roll is =${x} ` )
}, 1000,gRollOfStudent);
})
}
studentRol.then(( RollOfStudent)=>{
console.log(RollOfStudent); /** From here we are gating the Value OF student roll number */
mybiodata(RollOfStudent[1] /* this is First Argument OF ( mybiodata function )*/).then((fff)=>{
console.log(fff);
})
}).catch((x)=>{
console.log(x);
})
/*
A promise is a building object of JavaScript, using it we can easily do
asynchronous tasks. Also, the concept that is used to create clean code
basically promises.
*/
//Promise
let firstPromise = new Promise((resolved, reject) => {
let fullName = 'Muhammad Shahnewaz';
setTimeout(() => resolved(fullName), 3000); //we need to use setTimeout()
}).then((name) => {
console.log('I am ' + name); //Muhammad Shahnewaz
});
let dataIsLoading = true;
promise
.then(data => {
// do something with data
})
.catch(error => {
// do something with error
})
.finally(() => {
dataIsLoading = false;
})