- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设您有一个 OTP 进程,您希望同步等待其完成(其中“完成”可能是正常退出或崩溃、停止等)。
进一步假设出于业务原因,您无法使用 Task.async/1
生成此进程。或相关 Task
实用程序——它必须是一个不依赖于 Task.await/2
的“正常”进程.
有没有比简单地间歇性轮询更好的方法Process.alive?/1
?这让我印象深刻,因为这种事情可能有一个既定的模式,但对于我的生活,我找不到它。
def await(pid, timeout) when timeout <= 0 do
if Process.alive?(pid) do
Process.exit(pid, :kill) # (or however you want to handle timeouts)
end
end
@await_sleep_ms 500
def await(pid, timeout) do
# Is there a better way to do this?
if Process.alive?(pid) do
:timer.sleep(@await_sleep_ms)
await(pid, subtract_timeout(timeout, @await_sleep_ms))
end
end
最佳答案
Process.monitor/1
函数从调用进程监视给定进程。将此与 receive
结合使用,您可以对您的流程邮箱使用react。
defmodule Await do
def spawn do
Kernel.spawn(fn -> :timer.sleep(2000) end)
end
def await_down(pid) do
ref = Process.monitor(pid)
receive do
{:DOWN, ^ref, :process, ^pid, _reason} = message -> {:ok, message}
after
3000 -> {:error, :timeout}
end
end
end
pid = Await.spawn()
# => #PID<0.332.0>
Await.await_down(pid)
# => {:ok, {:DOWN, #Reference<0.4083290149.3661365255.180715>, :process, #PID<0.332.0>, :normal}}
注意接收块内的模式匹配,以确保消息不仅来自您的进程,而且来自特定的监控。
关于elixir - 等待 OTP 进程退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68397504/
Web OTP API 信息由 https://web.dev/web-otp 提供很好。但是 https://web-otp.glitch.me/ 中提供了演示目前正在使用版本 86.0.4240.
我正在尝试为我的 Android 版 Ionic 4 应用程序实现自动 otp 验证。我尝试了下面的代码,我能够收到消息,但 UI Input Filed 没有更新收到的 OTP app.compon
I have created Api for Verify mobile and i want to put some logic so that i can restrict the user wh
我有一个字符串:Rishav 应用 OTP 是:1232 我还有正则表达式:/^\b\d{ 4}\b/ 不知何故,当我测试正则表达式并将其与字符串匹配时,它显示错误。但当我在线测试正则表达式时,它会突
这个问题已经有答案了: how to design react native OTP enter screen? (9 个回答) 已关闭 3 年前。 我已经尝试过几篇文章来构建可定制的 OTP 组件,
我正在使用 Facebook AccountKit 进行 OTP 验证,它工作得非常好。 要求:通过读取收到的短信自动在 OTP 验证屏幕上设置 OTP 代码。 正在寻找:有什么方法可以将文本设置为
我想在我正在构建的分布式应用程序中使用 erlang 的 OTP 主管。但我无法弄清楚这种主管如何监控远程节点上运行的进程。与 erlang 的 start_link 函数不同,start_child
我正在阅读 Erlang 文档,试图了解设置 OTP gen_server 和主管的基础知识。每当我的 gen_server 崩溃时,我的主管也会崩溃。事实上,每当我在命令行上出现错误时,我的主管就会
我正在构建一个 Erlang/OTP 系统,它由 MochiWeb Web 服务器、一些自定义 Erlang/OTP 应用程序和一些非本地组件组成,如下所示: 一个 CouchDB 数据库,用于存储
我有兴趣对我的程序的不同部分进行基准测试以提高速度。我曾尝试使用 info(statistics)和 erlang:now()我需要知道平均速度是多少微秒。我不知道为什么我写的脚本有问题。 它应该能够
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
给定一个具有多个模块的工作 erlang 项目......想要热插拔多个依赖模块......是同步到新模块的过渡(全部或无)还是它们一次安装一个......这样任何飞行中的交易可能会产生不可预测的结果
给定一个具有多个模块的工作 erlang 项目......想要热插拔多个依赖模块......是同步到新模块的过渡(全部或无)还是它们一次安装一个......这样任何飞行中的交易可能会产生不可预测的结果
我想使用下面的代码片段来验证多个OTP。如果一个 OTP 正确,则应询问用户下一个问题。 4 个问题后,表达问候。 var question = prompt('Who shot Abraham Li
我正在尝试使用 this 阅读短信方法。但是我的应用程序没有读取消息。 我已经尝试过的代码。 权限: Activity (主要代码): class OtpActivity : AppCompat
我的应用程序中有 OTP 自动建议。它不适用于阿拉伯语,同样适用于英语和法语。那么有人可以帮助我吗? 最佳答案 短信必须包含“代码” 或“密码” 代码之前的任何语言权限的单词。 关于iOS OTP 自
我想使用短信和语音将 otp 代码发送给我的用户。我已经使用 clickatell 提供商通过短信完成了 otp 的发送。 我想通过向用户的电话拨出电话来实现同样的目的。就像,whatsapp 有发送
我需要一种算法来生成一种 OTP 代码。 6位数字输出(小数字填充'0') 没有状态数据(或数据库) 每个号码至少会间隔1ms(通常是几秒) 一小时后号码可以重复使用 我的第一次尝试: 用当前时间做一
我在看 django-otp模块并想在我的项目中实现它。但我面临着几个问题。 1) 根据文档(他们在文档中给出的方法),身份验证分为三个级别:Anonymous、Authenticated 和Auth
假设我有以下设置: defmodule NestedSupervisorTree do # this will be the top line supervisor use Superviso
我是一名优秀的程序员,十分优秀!