Open mmerkes opened 10 years ago
When writing applications with Node, an essential operation is querying a database and processing the data once it's received. How would the performance of our application be if we always had to wait for the database to return data before would could perform any other operation?
Fortunately, Node allows for asynchronous operations (meaning, non-blocking input and output operations). Given a method for our database defined as db.findAll( tableName, callback )
, write a program that finds all of the rows in the guestlist
table, and print out the first_name
and last_name
for each row returned in the console.
Does this look like an appropriate async exercise? I thought a more realistic operation would be better than the classic setTimeout examples. Any thoughts would be appreciated!
@mmerkes I do like that it's realistic, and geared towards node.js.
It could be a little much, but given the proper boilerplate, a couple links to resources to better understand async, this exercise could be extremely rewarding to beginners. It would feel like they've actually programmed something, rather than coded an arbitrary example.
One thing to keep in mind is there may be two types of people coming to this exercise. Some that don't understand programming at all, and some that want to learn JavaScript but has some basic understanding of programming. Both scenarios require a proper introduction to async and why it's important, but those coming from other languages may not understand the importance of async in node.
All things being equal, creating realistic exercises is better, but I agree that this may be pushing it. Once we start writing this out further, we can try to get a sense of how well it fits in, and to simplify things, we could switch out the operation performed in the callback to fit in with previous exercises. Regardless, the hard part will be writing a concise and clear explanation of async. I'll try to get the first draft going to people have something to iterate off of.
Once we get to the point of having something to use, I can try to take advantage of a huge aspiring developer community out in Seattle to try to get a little feedback.
Introduce and explain asynchronous programming