gen_server 自动停止的问题

52 views
Skip to first unread message

Rico

unread,
Jan 31, 2013, 9:30:28 AM1/31/13
to erlang...@googlegroups.com
我隐约记得好像在哪里描述过一个参数:如果 gen_server 在一定时间内没有收到任何消息,就自动停止。

记不清是那本书,或者是哪个项目里自定义的行为了,有人知道的么?


-- 
Rico
Sent with Sparrow

Feng Yu

unread,
Jan 31, 2013, 9:39:36 AM1/31/13
to erlang...@googlegroups.com
自动停止什么概念?gen_server的代码就在那里,没几行,看看就明白了。

专注高性能容错分布式服务器的研究和实现
http://blog.yufeng.info


2013/1/31 Rico <fei....@gmail.com>
--
您收到此邮件是因为您订阅了 Google 网上论坛的“Erlang China”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 erlang-china...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
 
 

Rico

unread,
Jan 31, 2013, 9:45:49 AM1/31/13
to erlang...@googlegroups.com
就是进程优雅结束。

文档代码都翻了,没找到这个功能,但是我好像又在哪里见到过。。

-- 
Rico
Sent with Sparrow

Wei Cao

unread,
Jan 31, 2013, 10:00:02 AM1/31/13
to erlang...@googlegroups.com
gen_server的init,handle_call和handle_cast返回值里不是都可以带一个timeout参数么,如果这个时间之内进程没收到其他消息,就会受到一个timeout消息,你可以在handle_info里处理这个timeout, 结束进程

如果timeout消息有其他用处,也可以自己定义个timer
Best,

Wei Cao

Lihe Wang

unread,
Feb 1, 2013, 12:19:06 PM2/1/13
to erlang...@googlegroups.com
同建议看源码。erlang的otp库虽然强大,但感觉真的很简单,难的是理念。gen_server基本就是个loop一直在转,没有自动停止这个功能。

bruce.xin

unread,
Mar 3, 2013, 8:24:05 AM3/3/13
to erlang...@googlegroups.com
gen_fsm才有超时参数吧

在 2013年1月31日星期四UTC+8下午10时30分28秒,Rico写道:

Lihe Wang

unread,
Mar 3, 2013, 6:05:42 PM3/3/13
to erlang...@googlegroups.com
超时参数是在gen.erl里给出的,默认5000毫秒。gen_server使用了gen。看源码啊~~


gen_fsm才有超时参数吧

在 2013年1月31日星期四UTC+8下午10时30分28秒,Rico写道:

Zhibin Zheng

unread,
Mar 3, 2013, 9:40:02 PM3/3/13
to erlang...@googlegroups.com
你说的是不是hibernate?

If hibernate is specified instead of a timeout value, the process will go into hibernation when waiting for the next message to arrive (by calling proc_lib:hibernate/3).

gen_server 每一个callback modules里面的result里。

BR.
Witeman

Reply all
Reply to author
Forward
0 new messages