A way to reduce nested code

83 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Andi

ungelesen,
02.06.2010, 11:44:4702.06.10
an nodejs
Is there a way to execute an asynchronous call as if it's synchronous,
which is useful in the most cases? Example: http://github.com/christkv/node-mongodb-native
This is the MongoDB driver for node.js and the example code won't do
anything but waiting for the callbacks and then starting the next
asynchronous call.
I have read that there is something like ...

asyncMethod().wait();
nextcall();

Guillermo Rauch

ungelesen,
02.06.2010, 12:10:5802.06.10
an nod...@googlegroups.com
The `coroutines` that we had for a while added a lot of complexity to the codebase, specially when dealing
with events, so they were dropped.
There're several strategies to make async code beautiful and practical (queues, promises are some).

One of our projects is mongoose, a library on top of node-mongodb-native that has exactly this goal (among
many others).

We're probably releasing 0.1 today, with a lot of bug fixes, enhancements, better documentation and specs.

--
Guillermo Rauch
http://devthought.com

Timothy Caswell

ungelesen,
02.06.2010, 18:27:0702.06.10
an nod...@googlegroups.com
I use my Step library, I also have one called Do, and one that I helped tmpvar with called Conductor.  Also there is the Promise library.

They are all four libraries that help mitigate the nesting without resorting to blocking apis.



--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.


tjholowaychuk

ungelesen,
03.06.2010, 09:56:2103.06.10
an nodejs
Personally I just recommend keeping your public apis abstracted and
short/sweet. I usually never nest more than 3 three times

Andi

ungelesen,
03.06.2010, 12:33:5303.06.10
an nodejs
Thanks, I will take a deeper look. I will use the one that comes
closest to:

var a, b = asyncCall(param);
useResults ...

instead of:
asyncCall(param, function (a, b) {
useResults ...
});
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten