[英]Warning: undefined callback function terminate/3 (behaviour 'gen_statem')**
這個警告有多嚴重? 我可以在這個警告中使用這個模塊嗎? 這個警告的副作用是什么。
警告:未定義的回調 function 終止/3(行為 'gen_statem')**
Erlang/OTP: 19.0.7
git clone https://github.com/inaka/apns4erl.git
cd apns4erl/
wget https://s3.amazonaws.com/rebar3/rebar3 && chmod +x rebar3
./rebar3 compile
===> Fetching coveralls v2.2.0
===> Fetching jsx v2.10.0
===> Analyzing applications...
===> Compiling jsx
===> Compiling coveralls
===> Verifying dependencies...
===> Fetching base64url v1.0.1
===> Fetching gun v1.3.3
===> Fetching jsx v3.0.0
===> Fetching cowlib v2.7.3
===> Analyzing applications...
===> Compiling cowlib
===> Compiling base64url
===> Compiling gun
===> Compiling jsx
===> Analyzing applications...
===> Compiling apns
**src/apns_connection.erl:22: Warning: undefined callback function terminate/3 (behaviour 'gen_statem')**
這個警告有多嚴重?
應該定義的 function 不存在。
我可以在這個警告中使用這個模塊嗎?
監督者使用 terminate() function 在必要時關閉子進程。 如果子進程永遠不需要關閉,那么你很好。
您可以在源代碼中添加無操作終止 function:
terminate(_Reason, _State, _Data) -> ok.
但是,更好的選擇可能是將錯誤報告給 github 存儲庫,希望他們能快速修復代碼。
或者,您可以嘗試升級您的 erlang 版本。 在較新的 erlang 版本中,為您自動定義了 terminate() function。
這個警告的副作用是什么。
您的程序在某些時候崩潰。
在 Erlang/OTP 19.3 及更高版本中,由於此更改, terminate/3
回調對於 gen_statem 是可選的。 如文檔中所述:
這個回調是可選的,所以回調模塊不需要導出它。 gen_statem 模塊提供了一個沒有清理的默認實現。
所以讓我們弄清楚在早期版本中不包括這個 function 的后果是什么。 根據文檔, terminate
function 將在三種不同的情況下被調用:
Actions
中返回了一個停止元組{stop,Reason}
brutal_kill
)'EXIT'
消息當然可以想象,對於特定的 gen_statem,這些情況都不會出現,因此缺少terminate
function 不會產生負面影響。 在最壞的情況下, terminate
function 將在進程即將退出時被調用,從而以與原始退出原因不同的退出原因終止進程,隱藏原始問題的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.