<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ahsanmalik07</title>
    <description>The latest articles on DEV Community by ahsanmalik07 (@ahsanmalik07).</description>
    <link>https://dev.to/ahsanmalik07</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F621953%2F9b5ec0c2-ecf2-4b3b-8a3f-8e844812d7c5.png</url>
      <title>DEV Community: ahsanmalik07</title>
      <link>https://dev.to/ahsanmalik07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahsanmalik07"/>
    <language>en</language>
    <item>
      <title>Promising your asynchronous operation</title>
      <dc:creator>ahsanmalik07</dc:creator>
      <pubDate>Wed, 28 Apr 2021 14:20:43 +0000</pubDate>
      <link>https://dev.to/ahsanmalik07/promising-your-asynchronous-operation-m9e</link>
      <guid>https://dev.to/ahsanmalik07/promising-your-asynchronous-operation-m9e</guid>
      <description>&lt;p&gt;Incase of multiple &lt;em&gt;async&lt;/em&gt; operations, the use of callback can quickly result in &lt;strong&gt;&lt;a href="http://callbackhell.com/"&gt;CALLBACK HELL&lt;/a&gt;&lt;/strong&gt;. Callback hell is when visually, execution is happening top to bottom.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j-JRrfZj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qozpxqvj4xqsgn0mk1ra.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j-JRrfZj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qozpxqvj4xqsgn0mk1ra.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the introduction of promise the chaining of functions was made simple and straightforward, simplified the code and improved its readability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promises in JavaScript&lt;/strong&gt;&lt;br&gt;
Promise is an JavaScript object that comprises of 3 states:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pending:&lt;/strong&gt; Initial State, before the Promise succeeds or fails&lt;br&gt;
&lt;strong&gt;Resolved:&lt;/strong&gt; Completed Promise&lt;br&gt;
&lt;strong&gt;Rejected:&lt;/strong&gt; Failed Promise&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D8uG1i5f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0p4bsqqu2w82qkc2z25.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D8uG1i5f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0p4bsqqu2w82qkc2z25.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Creating a promise is simple matter of calling the promise constructor. The &lt;em&gt;resolve&lt;/em&gt; and &lt;em&gt;reject&lt;/em&gt; functions for settling the promise state, are passed to the promise constructor:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EhCIHT4l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yp8rs00z8kmf0e574p7f.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EhCIHT4l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yp8rs00z8kmf0e574p7f.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A simple subscription can be made to the fate( settled state of promise) by using &lt;em&gt;.then&lt;/em&gt; (if resolved) or &lt;em&gt;.catch&lt;/em&gt; (if rejected).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dmuR_0qb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5uq5962i9ky65vss5ql.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dmuR_0qb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5uq5962i9ky65vss5ql.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UHztO-63--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0sez70cumvgdb0g7f63s.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UHztO-63--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0sez70cumvgdb0g7f63s.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WRAPPING UP&lt;/strong&gt;&lt;br&gt;
Promise is a broader topic that cannot be summed up in one article. The aim of this post was to get you familiarized with Promises in JavaScript and how to create and use them &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
