> 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.
On Fri, Jun 21, 2013 at 1:39 PM, Chaoran Yang <[email protected]> wrote: > > Dear all, > > I'm tired of the poor syntax of Step or Async or any other existing flow control libraries. I created a new flow control library in nodejs: Serialize (http://github.com/chaoran/node-serialize). > > Here's a brief introduction. There's more in the Github page. > > Serialize > > A simple node utility to serialize execution of asynchronous functions. > > What does it do? > > 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. > > How to use it? > > 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. > > > > -- > -- > 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 [email protected] > To unsubscribe from this group, send email to > [email protected] > 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 the Google Groups "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > -- -- 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 [email protected] To unsubscribe from this group, send email to [email protected] 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 the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
