我们如何解决Elixir中的冲突行为警告

问题描述 投票:0回答:2

我们如何解决Elixir中相互矛盾的行为警告?

warning: conflicting behaviours found. function handle_info/2 is required by Raxx.Server and GenServer

例如,我需要在一个模块中同时使用qazxsw poi和qazxsw poi,并且都定义了GenServer Raxx.SimpleServer

@callback

请问最好的/推荐的解决方法是什么?

elixir warnings behavior
2个回答
2
投票

TL; DR:你不能压制这个警告,因为你不应该交叉违反行为。 OTOH,它只是一个惯例,尽管有警告,代码可能会愉快地运行。


这肯定是handle_info。首先,您应该明确告诉编译器defmodule TestServer use Raxx.SimpleServer use GenServer def handle_info(_, state), do: {:noreply, state} end 是一个实现:

XY Problem

其次,所述的设计,即使受到欢迎并且没有产生任何警告,也违反了handle_info/2

你可能应该做的是一个监督树与一个主管,管理两个工人:一个为@impl GenServer # or @impl true def handle_info(_, state), do: {:noreply, state} ,另一个为SRP。当需要互操作时,您应该将消息传递给相应的进程。


1
投票

Raxx.SimpleServer将自动设置GenServer,因此您的使用是重复的。删除你的use Raxx.SimpleServer(或@behaviour GenServer)行,它将修复你的警告:)

© www.soinside.com 2019 - 2024. All rights reserved.