阅读了乔·阿姆斯特朗(Joe Armstrong)的书和观看了凯文·史密斯(Kevin Smith)的录屏,我构建了一个简单的 OTP 应用程序,由单个 gen_server 和单个 supervisor 组成,作为一个 OTP 应用程序捆绑在一起。
现在我正在研究 mochiweb,并使用 new_mochiweb.erl 脚本创建一个示例项目 [helloworld]。浏览源代码,我发现它与我的样本 OTP 应用程序 [OTP 应用程序已经存在,supervisor 也在那里] 并没有什么不同,只有一个关键区别……生成的 helloworld.erl 和 helloworld_web.erl 文件没有实现 gen_server 行为,它们只是标准的 Erlang 模块。
我曾经以为,在构建 OTP 应用程序组件时,使用 gen_server 是推荐的方法。为什么 mochiweb 使用 OTP 应用程序和 supervisor 行为,但回避 gen_server 呢?