ostinelli / syn

A scalable global Process Registry and Process Group manager for Erlang and Elixir.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I saw get_members_with_meta at https://github.com/ostinelli/syn/issues/7/1 method, why to the latest version, did not return this feature now

leeyisoft opened this issue · comments

commented

I saw get_members_with_meta at #7 method, why to the latest version, did not return this feature now( 3.3.0)

This method is very useful. Is there any other way to implement this requirement?

-spec get_members_with_meta(Name :: any()) -> [{pid(), any()}].
get_members_with_meta(Name) ->
    i_get_members_with_meta(Name).
commented

Preconditions:
Users can log in from multiple device types at the same time (e.g. on iOS, Android, MacOS, etc., one PID per device type).

Function implementation:
What I'm doing now is putting the Pids of multiple device logins into a group, and syn is perfect for that

Another feature, the user's device list, needs to show which devices are online.

前置条件:
用户可以同时用多中设备类型登录(比如同时在iOS 和 Android 还有MacOS 等设备上登录,每个设备类型一个PID)

功能实现:
我现在实现的功能是,把多个设备登录的PID放到一个group 里面,用syn 可以完美解决问题

还有另外一个功能,用户的设备列表,里面需要显示那些设备在线


In my IM project, this is my mnesia is used to implement this feature (https://github.com/imboy-pub/imboy/blob/main/src/chat_online.erl), I'm going to use https://github.com/ostinelli/syn to realize it

...

%%
% pid   进程ID
% uid   登录用户ID
% dtype 设备类型 web ios android macos windows等
% did   设备ID
-record(chat_online, {
          pid,
          uid,
          dtype,
          did
         }).

...

%% [{chat_online,<0.1155.0>,<<"1">>,<<"iOS">>,<<"78ece1d4d7d346a1">>}]
-spec lookup(pid() | integer()) -> list().
lookup(Pid) when is_pid(Pid) ->
    mnesia:dirty_read(chat_online, Pid);
lookup(UID) when is_integer(UID) ->
    lookup(integer_to_binary(UID));
lookup(UID) when is_list(UID) ->
    lookup(list_to_binary(UID));
lookup(UID) ->
    mnesia:dirty_index_read(chat_online, UID, #chat_online.uid).


lookup(UID, DID) ->
    [M1 || M1 <- lookup(UID), M1#chat_online.did =:= DID].

lookup_by_dtype(UID, Dtype) ->
    [M1 || M1 <- lookup(UID), M1#chat_online.dtype =:= Dtype].
...