我是Elixir的新手,我正在尝试开发向所有其他对等方发送给定数量消息的对等方。此外,在指定的时间之后,节点应停止广播和接收消息。我的问题是如何使其同时发送和接收消息?第二个问题是如何为此设置超时。这是我当前的代码:
messages_sent = Map.new()
messages_received = Map.new()
receive do
#Distribute messages
for dest <- peers, do:
for i <- 0..max_broadcasts, do: #Max broadcast specifies how many messages send to each peer
send dest, { :peer_broadcast, self()}
#Adds peer to map or update if it is already present
Map.update(messages_sent, dest, 0, &(&1 + 1))
end
end
#Receiving messages
{ :peer_broadcast, peer} ->
Map.update(messages_received, peer, 0, &(&1 + 1))
end #receive