title: how to make sure callback of one function call, gets executed only after callback of the second function call
body: <p>I am trying to parse a pdf containing data in the form of a table using javascript. My pdf file is a university  time table in the form of a grid which has data in each grid.
  I am making use of pdfreader npm package(I am quite new to javascript so I am not sure if a better package exists for the usecase)</p>
  <p>My plan is first parse through the pdf and with the help of few words I know are present in time table(eg name of days) and fetch  the approximate x and y  cordinates of the grid in the pdf. Secondly Parse throgh the pdf once again and now from the text I get populate some 2d array with the help of cordinates I fetched in first pass.</p>
  <p>In the sample for pdf parser there is a function, parseFileItems which  calls itemHandler(error, item) on each item parsed from the pdf file. So for the first pass I call the function like</p>
  <pre><code>  new PdfReader().parseFileItems(&quot;./timetable.pdf&quot;, (err, item) =&gt; {
      if (err) console.error(&quot;error:&quot;, err);
      else if (!item) console.warn(&quot;end of file&quot;);
      else if (item.text) {
          
          cordinatesofGrid=//my logic to fetch the cordinates of the grid
      }
    });
  </code></pre>
  <p>Now what I need to do is to parse through the pdf once again and make use of the &quot;cordinatesofGrid&quot; variable I have fetched in the first pass. so I again intend to call parseFileItems second time. But this should happen only once the first pass and its callback code is done executing.</p>
  <p>I tried to call the first parseFileItems with await and then call parse function second time but this is not working as expected. (I assume this is because the wait does not apply to the callback)</p>
  <pre><code>  await new PdfReader().parseFileItems(&quot;./timetable.pdf&quot;, (err, item) =&gt; {
      //first call 
    });
    
    new PdfReader().parseFileItems(&quot;./timetable.pdf&quot;, (err, item) =&gt; {
      //second  call 
    });
    
  </code></pre>
  <p>Could anybody suggest how to make sure callback of one fucntion call, gets executed only after callback of the second function call</p>