简体   繁体   English

如何捕获偏航过程出口?

[英]How can I trap process exits in yaws?

A separate Erlang chat server stores all PIDs in a mnesia table and groups them under a Room ID so when a user sends a message, A gen_server sends the message to all processes under that Room ID. 单独的Erlang聊天服务器将所有PIDs存储在mnesia表中,并在Room ID下对其进行分组,因此,当用户发送消息时, gen_server会将消息发送到该Room ID下的所有进程。

so far everything works great but the problem is: 到目前为止,一切正常,但问题是:

When the user subscribes to the server, The server sends a message to all pids to notify subscribers about a new subscriber, however I cannot think of/know a practical way to do reverse of it. 当用户订阅服务器时,服务器会向所有pids发送一条消息,以通知订阅者有关新订阅者的信息,但是我想不出/不知道有一种实用的方法可以pids订阅。

I need to let people know that a subscriber has unsubscribed and remove the pid from the table. 我需要让人们知道订户已取消订阅并从表中删除该pid。 How can I implement such supervsor in yaws? 如何在偏航supervsor中实现这样的supervsor

When the server sends a message to all pids to notify them of a new subscriber, have it also notify a process whose job is to erlang:monitor/2 each new subscriber process. 当服务器向所有pid发送消息以通知它们有新订阅者时,还让它通知工作为erlang:monitor/2每个新订阅者进程的进程。 That process, a gen_server , could keep a table of some sort as its state, like a map , dict , or ets table, that stores the reference returned from erlang:monitor/2 along with the associated room ID. 该进程gen_server可以保留某种状态的表,例如mapdictets表,该表存储从erlang:monitor/2返回的引用以及关联的房间ID。 When a subscriber process dies, the monitor process will receive a {'DOWN', MonitorRef, Type, Object, Info} message via its gen_server:handle_info/2 function , and it can then look up the MonitorRef in its state and notify the associated room of the dropped subscription. 当订阅者进程{'DOWN', MonitorRef, Type, Object, Info}监视进程将通过其gen_server:handle_info/2函数接收{'DOWN', MonitorRef, Type, Object, Info}消息,然后可以在其状态下查找MonitorRef并通知相关联删除订阅的空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM