How do i implement this pattern in node js?
<p>I am writing a data access layer where in my dalmethod will be called &amp; after work is done by the callers, I have to close the db.</p>

<p>I dont want to bother the callers for closing my db (or performing some other operations). </p>

<p>Basically i am looking out for some synchronicity in my asynchronous operations (promises?).</p>

<p>Following is a pseudo code.</p>

<pre><code>//For simplicity , assume they are in same file.

function Caller ()
{
  dalmethod(function(err,db){
     do some thing
     // I am done here
   });

}

function dalmethod(callback)
{
// Connect database &amp; call this function

  callback(somevalue,db);
 //after call back function is executed call some more methods. such as closing the db.
  // db.close();
}

Caller();
</code></pre>