Β
* StartTime (parameter if we are late for work or not)
const morningRoutine = async (startTime) => {
};
Create an "Async" function
const drinkWater = (time) => new Promise(resolve, reject) => {
resolve (time);
}
const morningRoutine = async (startTime) => {
const step1FinishTime = await drinkWater(startTime)
};
Create an "Async" function
const drinkWater = (time) => new Promise(resolve, reject) => {
resolve (time);
}
const shower = (time) => new Promise(resolve, reject) => {
resolve (time);
}
const morningRoutine = async (startTime) => {
const step1FinishTime = await drinkWater(startTime)
const step2FinishTime = await shower(step1FinishTime)
};
Create an "Async" function
* startTime (parameter if we are late for work or not)
const morningRoutine = async(startTime) => {
Promise 1 resolves
π’<------------------------π₯
|
|____pass_val
|_to_promise 2___
|
Promise 2 resolves |
π’<------------------------πΏ
}
Logic
const drinkWater = (time) => new Promise(resolve, reject) => {
resolve (time);
}
const shower = (time) => new Promise(resolve, reject) => {
resolve (time);
}
const morningRoutine = async (startTime) => {
const step1FinishTime = await drinkWater(startTime)
const step2FinishTime = await shower(step1FinishTime)
const step3FinishTime = await getDressed(step2FinishTime)
const step4FinishTime = await drinkJuice(step3FinishTime)
const step5FinishTime = await trenzarPelo(step4FinishTime)
const step6FinishTime = await drinkCoffee(step5FinishTime)
return step6FinishTime;
};
Create an "Async" function
const drinkWater = (time) => new Promise(resolve, reject) => {
resolve (time);
}
const shower = (time) => new Promise(resolve, reject) => {
resolve (time);
}
const morningRoutine = async (startTime) => {
try{
const step1FinishTime = await drinkWater(startTime)
const step2FinishTime = await shower(step1FinishTime)
const step3FinishTime = await getDressed(step2FinishTime)
const step4FinishTime = await drinkJuice(step3FinishTime)
const step5FinishTime = await trenzarPelo(step4FinishTime)
const step6FinishTime = await drinkCoffee(step5FinishTime)
return step6FinishTime;
}
catch (e) {
return e;
}
};
Using βTryβ and βCatchβ In the Async Function
const morningRoutine = async(startTime) => {
try{
1π’<------------------------π₯
|_________________________
|
2π’<------------------------πΏ
|_________________________
|
3π’<------------------------π
|_________________________
|
4π’<------------------------ππ
|_________________________
|
5π’<------------------------πΏ
|_________________________
|
6π’<------------------------βοΈ
}
catch (e) {
return e;
}
}
Logic
const morningRoutine = async(startTime) => {
try{
1π’<------------------------π₯
|_________________________
|
2π’<------------------------πΏ
|_________________________
|
3π’<------------------------π
|_________________________
|
4π’<------------------------ππ
|_________________________
|
5π’<------------------------πΏ
|_________________________
|
6π’<------------------------βοΈ
}
catch (e) {
return e;
}
}
Logic
@luucamay_