Promise function example

this example contains promise all. allsettled, race and any codes

by Sunny SM

JavaScript

const employeeDetail = new Promise((resolve, reject) => {
	setTimeout(() => {
  	resolve({
    	status: 'success',
    	message: 'This promiseExample 1 function resolved',
      data: [{
      	name: 'employee 1',
        address: 'Chandigarh',
        post: 'Clerk',
        salary: 15000
      },
      {
      	name: 'employee 2',
        address: 'Delhi',
        post: 'Manager',
        salary: 25500
      }]
    });
  }, 1000);
});
const employeeBankDetail = new Promise((resolve, reject) => {
	setTimeout(() => {
  	resolve({
    	status: 'success',
    	message: 'This promiseExample 2 function resolved',
      data: [{
      	name: 'employee 1',
        bankAccountName: 'HDFC Bank',
        BankAccountNumber: '1213442343443533',
        BankCode: 'HDFC000343'
      },
      {
      	name: 'employee 2',
        bankAccountName: 'SBI Bank',
        BankAccountNumber: '98989732412',
        BankCode: 'SBI00002201'
      }]
    });
  }, 500);
});
const employeeDeductions = new Promise((resolve, reject) => {
	setTimeout(() => {
  	resolve({
    	status: 'success',
    	message: 'This promiseExample 3 function resolved',
      data: [{
      	name: 'employee 1',
        pf: 3200,
        insurence: 1200,
        medicalPrimium: 850
      },
      {
      	name: 'employee 2',
        pf: 3200,
        insurence: 2500,
        medicalPrimium: 600
      }]
    });
  }, 1200);
});
const employeeAttendance = new Promise((resolve, reject) => reject('employee data  not found'));

/**
* Promise all method takes an iterable  of promises as in input and return a single promise that resolves to an array of the results of the input promises. his returned promise will resolve when all of the input's promises have resolved.
* It rejects immediately upon any of the input promises rejecting or non-promises throwing an error, and will reject with this first rejection message / error.
*/
/*
const employeesData = Promise.all([employeeDetail, employeeBankDetail, employeeDeductions,...