简体   繁体   English

有没有办法为 erlang 中的生成进程 make_ref() ?

[英]Is there a way to make_ref() for spawned processes in erlang?

I have tried to make references to spawned processes in erlang in several ways in order to make them compatible with the logging of From in a call to gen_server .我尝试以多种方式引用 erlang 中生成的进程,以便使它们与调用gen_serverFrom的日志记录兼容。 So far I have tried P1ID = {spawn(fun() -> self() end), make_ref()}, in order to capture the structure of from() as stated in the documentation about gen_server:reply : erlang documentation I have not yet succeeded and the documentation about make_ref() is rather scarce.到目前为止,我已经尝试过P1ID = {spawn(fun() -> self() end), make_ref()},以捕获from()的结构,如有关gen_server:reply的文档中所述:我有erlang 文档尚未成功,关于make_ref()的文档相当稀缺。

were you attempting to built that {Pid, Ref} tuple in order to test the handle_call() gen_server callback from your tests?您是否试图构建 {Pid, Ref} 元组以测试测试中的 handle_call() gen_server 回调?

if yes, you should not test these gen_server internals directly.如果是,则不应直接测试这些 gen_server 内部结构。 instead add higher level functions to your module(that will call the gen_server call/cast/.. functions) and test those而是向您的模块添加更高级别的函数(这将调用 gen_server 调用/转换/.. 函数)并测试它们

spawn() already returns a pid() so there was no reason to return self() from from the spawned process. spawn() 已经返回一个 pid() 所以没有理由从生成的进程中返回 self() 。

Hope it helps希望能帮助到你

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

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