Question

I'm using Express for a project, and I've been trying out the CouchDB database using Cradle. While the idea of asynchronous execution is cool for performance reasons, it's making my code really a mess for routines where I need to make several database calls in a row.

Is it possible to make cradle calls without using a callback? Or, I suppose more correctly, is there a better way to organize the code that doesn't involve nesting 3 or 4 anonymous functions within one another just to get at database query results? The code is only used in one place, so it doesn't make sense to me to use named functions that will only be called once.

Was it helpful?

Solution

Is it possible to make cradle calls without using a callback?

As far as I know cradle has only asynchronous API.

Or, I suppose more correctly, is there a better way to organize the code that doesn't involve nesting 3 or 4 anonymous functions within one another just to get at database query results?

I would first recommend to read following articles on flow control topic in order to get a bigger picture of what's going on:

Then you can make things simple and take advantage of several flow control libraries which deals with issues of asynchronous code in node.js:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top