commonjs异步模块

如何包装基础性的异步模块,有几种方案:

1.包装到对象属性上

var Wrapper = function(){
  this.foo = "bar";
  this.init();
};
Wrapper.prototype.init = function(){
  var wrapper = this;  
  async.function(function(response) {
    wrapper.foo = "foobar";
  });
}
module.exports = new Wrapper();

2.Promise

按规范来import和export即可

3. MQ

用zeroMQ之类的进行队列投递

最近的文章

发布brew个人包

Mac上的包管理工具,一般都推荐使用homebrew。homebrew开源在github上,其中formula文件夹为brew收录的所有包,目前大概是4000个。但是个人制作的小软件不会被官方仓库的formula收录,homebrew官方留出了tap命令使得我们可以将homebrew-core部署到自己的仓库,这样就可以用brew安装我们指定路径下的可执行文件,并将其安装到/usr/lcoal/bin目录下…

继续阅读
更早的文章

某段ruby元编程

可以用irb(Ruby的REPL程序)实际运行:class A [:scope, :show_snippets, :search_results, :search_objects].each do |name| define_method name do search instance_variable_get "@#{name}" end end def search return if @searched @scope, @show_s...…

继续阅读