Hello.

If you spend enough time in node.js you will eventually run into the need of a
control flow library. Creating your own control flow library is almost the hello
world of node.js.

My library is called async-array.

  var async = require('async-array').async
  var mysql = require('mysql').createConnection()
  mysql.connect()

  function mysqlmap (query, i, next) {
    mysql.query(query, next)
  }

  function mysqldone (err, results) {
    // OMG There was an error somewhere. Handle it houston.
    if (err) throw err

    // Change results from an AsyncArray back to a normal array.
    results.array()

    // Results are mapped to the same place as the query.
    results[0]
    results[1]
  }

  async(
    [ 'SELECT * FROM my_ultimate_table'
    , 'SELECT bacon FROM the_fridge'
    ]
  )
    .map(mysqlmap)
    .exec(mysqldone)

It tries to keep the basic semantics of a normal array, adding some asyncronous
magic. https://github.com/tim-smart/async-array

Tim.

On Tue, Dec 25, 2012 at 09:14:27AM -0800, Joman Sierra wrote:
> I have this scenario:
> 
> function one
> {
> Makes a query to a big mysql table
> 
> }
> 
> Function two
> {
> Makes another query to a big myslq table
> }
> 
> res.render(showing results of the queries)
> 
> 
> The problem is that when render is executed the mysql queries are still in 
> progress.  What's the best way to be sure that the functions has finished 
> before sending the render?
> 
> -- 
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: 
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to