<?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: Ajay Bhosale</title>
    <description>The latest articles on DEV Community by Ajay Bhosale (@bhosaleajay).</description>
    <link>https://dev.to/bhosaleajay</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%2F360963%2F7daf286b-79c2-4a1b-8476-7c0fbe8e9170.jpeg</url>
      <title>DEV Community: Ajay Bhosale</title>
      <link>https://dev.to/bhosaleajay</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bhosaleajay"/>
    <language>en</language>
    <item>
      <title>Understanding levels of responsibilities to move up in the career ladder</title>
      <dc:creator>Ajay Bhosale</dc:creator>
      <pubDate>Mon, 03 Aug 2020 02:24:25 +0000</pubDate>
      <link>https://dev.to/bhosaleajay/understanding-levels-of-responsibilities-to-move-up-in-the-career-ladder-47c8</link>
      <guid>https://dev.to/bhosaleajay/understanding-levels-of-responsibilities-to-move-up-in-the-career-ladder-47c8</guid>
      <description>&lt;p&gt;If you have worked at a large software organization, I am sure you may have faced following questions at some point in time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is the difference between a software engineer and a senior software engineer? Or a between a team lead and delivery manager?&lt;/li&gt;
&lt;li&gt;How to move up in the hierarchy?&lt;/li&gt;
&lt;li&gt;What does it mean to really grow in career?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many times the sense of progress is associated with a job title and the scope of responsibility. Job titles can be misleading, and organizations tend to create them just to give a sense of movement, without much change in scope or nature of responsibilities.&lt;/p&gt;

&lt;p&gt;From my experience, there are four levels of responsibilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Responsibility of presence&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Being there, both physically and mentally. This looks pretty oblivious, but whether you have just started a job or doing it for 10 years, once in a while you will find it difficult to fulfill this responsibility. Some organizations have ways to enforce the physical presence, but mental presence is still an individual territory. For a person who is new at a job or at the first level of the hierarchy, this is their primary responsibility. Be there, listen, learn, ask questions, and understand the context. Do note that you can’t keep lingering at this level forever.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Responsibility of efforts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Putting efforts towards the assigned task. Acquiring, and improving on competencies required to perform these tasks. One can also help their co-workers to move from responsibility of presence to responsibility of efforts. This will be the key responsibility for someone who can work with a little bit or no guidance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Responsibility of output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;From here you take ownership and start being accountable. You work with those who are responsible for efforts and ensure that those efforts have desired output, on time, on schedule, and with required quality attributes. It is also important to note that those who are responsible for efforts may or may not report to you directly or indirectly. You will also invest time in mentoring and building teams which can consistently produce the output.&lt;/p&gt;

&lt;p&gt;At an advanced level of this stage, you also work as a translator who can translate the direction and vision from senior leadership into actionable tasks which can be performed who are responsible for efforts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Responsibility of outcome&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the last stage, where you are accountable for the desired outcome from the business perspective. If you are an experienced person, then you might have worked on a project which passed the output test but failed to produce the desired business outcome. At this stage, your primary job is achieving the output getting realized as outcome.&lt;/p&gt;

&lt;p&gt;This responsibility demands that you provide vision, direction, advise and required resources to folks who are responsible for output. You need to be comfortable with the fact that your reward will be based on the outcome and not on efforts. Almost 99% of time outcome is measured objectively in terms of numbers like revenue, and profit.&lt;/p&gt;




&lt;p&gt;Now moving up in the hierarchy can be simplified as taking the next level of responsibility as mentioned above, or increasing the scope of the current responsibility. Most organizations like to see the demonstration of your ability to perform the next level of responsibility before your official movement.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don’t target role, target activities &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One key advise I got from a mentor is instead of targeting for a next level role target for activities that you want to perform at that role. Come up with proposals to improve things or start/own initiatives which normally owned by the person at the next level. This will help to build your case, demonstrate your appetite as well as the capabilities for next level of responsibility.&lt;/p&gt;

&lt;p&gt;So what you are responsible for?&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>Lessons learned while working as an architect — Part II</title>
      <dc:creator>Ajay Bhosale</dc:creator>
      <pubDate>Tue, 14 Jul 2020 15:06:34 +0000</pubDate>
      <link>https://dev.to/bhosaleajay/lessons-learned-while-working-as-an-architect-part-ii-4c7p</link>
      <guid>https://dev.to/bhosaleajay/lessons-learned-while-working-as-an-architect-part-ii-4c7p</guid>
      <description>&lt;p&gt;Few years back I wrote about lessons learned while working as an architect, &lt;a href="https://dev.to/bhosaleajay/lessons-learned-while-working-as-an-architect-388k"&gt;you can read them here&lt;/a&gt;. Since then my role changed from an architect who works on implementation projects for a single customer to an architect who consults teams from multiple customers spanning different industries. Here are some new lessons I learned external consultant/architect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accept the fact that efforts realization will be low
&lt;/h2&gt;

&lt;p&gt;While working on a single project, all you care about is details, and make it work. It’s a fulfilling job with a high realization of efforts, the outcome benefits end users, sometimes you need course correction, but you learn as part of that process which is also fulfilling. Consulting on the other hand is very different, you are always on the move, switching context, effort realization is very low, you spend time on things like POC, RFP, and RFI which may get scrapped suddenly. This impacts your motivation, and you may feel out of action. By accepting the nature of consulting business you will be able to cope with low realization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use/suggest patterns/styles/practices without naming them
&lt;/h2&gt;

&lt;p&gt;Using loaded terms like Microservices to explain proposed design invites unproductive debates. The discussion moves to advantages vs disadvantages of said practice, everyone starts throwing buzzwords, and it derails the focus from the actual problem. What I learned is to just use the underlying idea, for example instead of saying “Microservice Architecture”, I say “Modular services holding their own data, using asynchronous channels and crisp messages for communication”. This removes unnecessary resistance and bias. This advice looks contrary to practice of naming patterns to ease the communication, but I found it very effective.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect with real decision maker(s) and end users
&lt;/h2&gt;

&lt;p&gt;As an external consultant, it takes time to get access to real decision makers within the customer organization. Sometimes the org structure does not reflect real flow of decision making and influence. Finding the key decision makers, opening a communication channel with them, and establishing trust is key for success. There is no formula for this, you have to observe, listen, and follow the memos (like follow the money). On the other hand, finding end users is easy, but getting access to them is very difficult for external consultants. Organization policies, politics, and culture builds multiple barriers between you and the end users. Connecting with end users, and understanding their needs helps you to distill the problem statement. It helps you to ensure that you are building the right thing for the right people, and deliver it incrementally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understand and pick your battles
&lt;/h2&gt;

&lt;p&gt;As an architect providing appropriate technology solutions to a business problem is your primary battle. Defining the problem is also a battle, navigating a complex org structure for information is another one, and so is selling your solution. Each battle requires different skills, you can’t master them all. You have to pick your battles, work with your team to augment skills which you don’t have and support them for remaining battles.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>leadership</category>
      <category>career</category>
      <category>learning</category>
    </item>
    <item>
      <title>Lessons learned while working as an architect</title>
      <dc:creator>Ajay Bhosale</dc:creator>
      <pubDate>Tue, 14 Jul 2020 15:04:37 +0000</pubDate>
      <link>https://dev.to/bhosaleajay/lessons-learned-while-working-as-an-architect-388k</link>
      <guid>https://dev.to/bhosaleajay/lessons-learned-while-working-as-an-architect-388k</guid>
      <description>&lt;p&gt;Over the last 12 years, I played role of solution architect on multiple projects. Here is summary of lessons I learned over the period.&lt;/p&gt;

&lt;h2&gt;
  
  
  Need for embracing ambiguity
&lt;/h2&gt;

&lt;p&gt;As a developer, our demand for clear requirements is very logical. As an architect, it’s totally different story. For most of the projects, the requirements aren’t clear, partner systems aren’t ready, business analyst is in dual mind, and despite all this chaos you are expected to come up with a strong design. At start (especially if it is your first assignment as an architect) this becomes very frustrating, but as you start to live with this ambiguity your approach becomes adoptive. One key trap to avoid here is to build a design to satisfy imaginary future requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consistency in decision making with the help of guiding principles
&lt;/h2&gt;

&lt;p&gt;Consistency will help you to quickly gain trust with team and customers. The guiding principles should be based on good practices, non-functional requirements, specific project needs etc. Note that principles should not be rigid but evolve over the period, and needs to be followed in the spirit (and not the text). As the team understands the reasoning behind your decisions and starts adopting the principles, bottleneck on you for every other decision will be reduced.&lt;/p&gt;

&lt;p&gt;Some of the examples of guiding principles — “Lower memory footprint”, “Performance over data duplication”, or “No single point of failure”&lt;/p&gt;

&lt;h2&gt;
  
  
  Be there on shop floor
&lt;/h2&gt;

&lt;p&gt;There is no point in being a visio architect, who keeps churning out fancy diagrams. As an architect, you must work with engineering teams, let them be involved in decision making. If possible, do pair programming with them to get first-hand experience of their challenges and how your own design is getting implemented.&lt;/p&gt;

&lt;h2&gt;
  
  
  Influencing without authority
&lt;/h2&gt;

&lt;p&gt;Recently during a mentoring session, a senior developer told me that he doesn’t wants to be a manager because it involves lots of communication and interaction with others, but as an architect, he can work alone. This is a huge misconception. As an architect, one must learn to communicate and influence. As a manager, I don’t need to explain (most of the times) logic behind my decisions, I can simply dictate the things. But this is not a case with architect, you need to communicate to various stakeholders, understand each view point, influence developers/testers who don’t report to you.&lt;/p&gt;

&lt;p&gt;On a lighter note, most difficult task as an architect is to convince developers and other parties to move to a better design from the current design, which you yourself has created few months (or days) back.&lt;/p&gt;

&lt;p&gt;Thanks for reading, feel free to like, comment and share.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>leadership</category>
      <category>career</category>
      <category>learning</category>
    </item>
    <item>
      <title>async, await, and keeping your promises </title>
      <dc:creator>Ajay Bhosale</dc:creator>
      <pubDate>Fri, 15 May 2020 03:58:15 +0000</pubDate>
      <link>https://dev.to/bhosaleajay/async-await-and-keeping-your-promises-2h5e</link>
      <guid>https://dev.to/bhosaleajay/async-await-and-keeping-your-promises-2h5e</guid>
      <description>&lt;p&gt;The &lt;code&gt;async function&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; keyword introduced as part of ECMAScript 2017 do provide very useful syntactic sugar on top of promises. &lt;code&gt;Promise&lt;/code&gt; in itself provides alternative to callbacks when writing asynchronous code. Promises can be chained, its inbuilt methods like &lt;code&gt;all&lt;/code&gt;, &lt;code&gt;any&lt;/code&gt;, and &lt;code&gt;race&lt;/code&gt; helps to manages multiple asynchronous tasks.&lt;/p&gt;

&lt;p&gt;Check the following example, here &lt;code&gt;getData&lt;/code&gt; function mimics asynchronous behavior. In real world, you can think it as your data layer, using functions like &lt;code&gt;fetch&lt;/code&gt; or a 3rd party library which still using callbacks for asynchronous programming.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rej&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;rej&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Can not use 3.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If I have to, fetch data for 2, and based on that response fetch data for 3 and 4, then the code will look like something below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;check&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x2&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x3&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x4&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// This is catch handler&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error occurred : Check with Promise.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If we used async and await, same code will be more readable and easy to understand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;check&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;x3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;x4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// This is catch block&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error occurred : check with async and await.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Error handling, is still a challenge. If a promise is rejected, then either the catch handler get executed, or an exception will be thrown. With &lt;code&gt;await&lt;/code&gt; keywords, only way to handle rejected promise is &lt;code&gt;try-catch&lt;/code&gt; block.&lt;/p&gt;

&lt;p&gt;This may work for some cases, but what if you are fine with errors while loading data for 3 and 4. The catch block does not give a good way to handle control flow. You may end up having separate &lt;code&gt;try-catch&lt;/code&gt; blocks for each &lt;code&gt;await&lt;/code&gt;, and that will worsen the problem.&lt;/p&gt;

&lt;p&gt;Languages like &lt;code&gt;go&lt;/code&gt;, has a different philosophy to handle errors. It segregates &lt;code&gt;error&lt;/code&gt; from &lt;code&gt;exception&lt;/code&gt;, and communicate errors with ordinary values as return parameters.&lt;br&gt;
Lets see what happens when we try that philosophy here.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Always keep your promises&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let change the getData function so that it can never reject the promise. The promise will be always resolved, and errors will be reported via a return type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;PromiseResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PromiseResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// no reject here &lt;/span&gt;
            &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Can not use 3.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I have declared a Type here &lt;code&gt;PromiseResponse&lt;/code&gt;, which is a Promise returning tuple, and will assist TypeScript for better syntax checking.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First item will be error : string or null.&lt;/li&gt;
&lt;li&gt;Second item will be actual result of Type T or undefined.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;check3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;e2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;getDataV2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Here for TypeScript x2 is either number or undefined&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x2&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error while fetching data for 2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// As x2 is checked for undefined&lt;/span&gt;
    &lt;span class="c1"&gt;// at this line x2 is number&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// now fetch data for 3 and 4&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;e3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;getDataV2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x3&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;e4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;getDataV2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x4&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With the new approach, code don't need to use &lt;code&gt;try-catch&lt;/code&gt; block and we have better control over flow.&lt;/p&gt;

&lt;p&gt;I am using this techniques for application layer, which seats between UI and underlying data, and its make life much easier.&lt;/p&gt;

&lt;p&gt;Based on your requirements, you can extend the Type &lt;code&gt;PromiseResponse&lt;/code&gt; into a class, and with helper methods like &lt;code&gt;Success&lt;/code&gt; and &lt;code&gt;Error&lt;/code&gt; to make your code more readable.&lt;/p&gt;

&lt;p&gt;I have a utility function, named as &lt;code&gt;aKeptPromise&lt;/code&gt; on propose. With this function getData is more readable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;aKeptPromise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;PromiseResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getDataV3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PromiseResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;aKeptPromise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Can not use 3.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://bit.ly/3dSOssW"&gt;TypeScript Playground&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading. Let me know if you have comments.&lt;/p&gt;

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