Frontend/24_10_14/promise_exercise.js

58 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-10-14 11:15:57 +00:00
/*
let mypromise = new Promise((resolve, reject) => {
let istrue = false;
if (istrue){
resolve("resolved");
} else {
reject("rejected");
}
});
mypromise.then((resolve) => {
console.log(`resolved: ${resolve}`);
}).catch((reject) => {
console.log(`rejected: ${reject}`);
});
*/
function elso(value){
return new Promise((resolve) => {
setTimeout(() => {
console.log(value);
resolve(value);
}, 3000);
});
}
function masodik(value){
return new Promise((resolve) => {
setTimeout(() => {
console.log(value);
resolve(value);
}, 2000);
});
}
function harmadik(value){
return new Promise((resolve) => {
setTimeout(() => {
console.log(value);
resolve("Minden lépés teljesítve");
}, 1000);
});
}
function asd(){
elso(1)
.then((value) => masodik((value + 1)))
.then((value) => harmadik((value + 1)))
.then((message) => {console.log(message);});
}
let num = 0;
setTimeout(() => {console.log("Ez az üzenet 3 másodperc után megjelenik.")}, 3000);
let ismetles = setInterval(() => {num++;console.log("Ez az üzenet 3 másodpercenként megjelenik.");}, 3000);
clearInterval(ismetles);