문제

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.

도움이 되었습니까?

해결책

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:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top