Thuta Learning
ရှာဖွေရန်
AdvancedProgrammingbeginner

JS Promises

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Promises များသည် asynchronous operation တစ်ခု၏ နောက်ဆုံး result ကို ကိုယ်စားပြုသော object ဖြစ်သည်။ Operation ပြီးဆုံးသောအခါ (succeed or fail) .then() (အောင်မြင်လျှင်) နှင့် .catch() (ကျရှုံးလျှင်) methods များဖြင့် ထို result ကိုကိုင်တွယ်နိုင်သည်။

javascript
const myPromise = new Promise((resolve, reject) => {
  let success = true;
  if (success) {
    resolve("The operation was successful!");
  } else {
    reject("The operation failed.");
  }
});

myPromise
  .then((message) => {
    console.log(message);
  })
  .catch((error) => {
    console.error(error);
  });
You should see
The operation was successful!
JS Promises | Thuta Learning