A simple node utility to serialize execution of asynchronous functions.
Asynchrony in nodejs is great, except that it makes your code looks horrible because of all the callbacks. If you use synchronous functions, which give you good-looking, easy-to-read code, they will block the thread and make your server not responsive.
Here's serailize to the rescue! serialize converts your asynchronous functions into serialized versions. Serialized functions are executed one after another, without explicitly chaining them with callback functions.serialize does NOT execute the function synchronously (block the thread), it just serialize the execution of asynchronous functions. So that it makes the code looks synchronous, but it is actually ascynhronous underneath.
To create a serialized version of an asynchronous function, call serialize with it. For example, if you want to make serialized versions of fs.writeFile and fs.mkdir, you do:
var serialize = require('serialize'); fs.mkdir = serialize(fs.mkdir); fs.writeFile = serialize(fs.writeFile);
Then, you can use fs.mkdir and fs.writeFile like they are synchronous functions:
fs.mkdir('new'); fs.mkdir('new/folder'); fs.writeFile('new/folder/hello.txt', "hello world", callback);
These function will be executed one after another, but they will not block the thread as their synchronous versions do. The callback will be invoked after the last call completes.
> fs.mkdir = serialize(fs.mkdir);
I assume you wouldn't really want to clobber fs. Wouldn't every other use of fs.mkdir break? I'd name it fsmkdir or something.
--
--
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 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?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/oH6XyOJNWwM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.