最初に断わっておくが、無視し続けても何も困らない可能性があるので、このページを見ても、内容は直ぐに忘れてもらっても構わないと思う。
gen_server:start_link/3, 4
の返り値に ignore
がある。
これはどういう時に返ってくるかというと Module:init/1
で ignore
を返した時である。
If
Module:init/1
returns{stop,Reason}
orignore
, the process is terminated and the function returns{error,Reason}
orignore
, respectively.
Module:init/1
が{stop, Reason}
またはignore
を返すと、プロセスは停止し関数はそれぞれ{error, Reason}
かignore
を返す。
さて、この ignore
、何に使うかというと supervisor
のページを見れば理由がわかる。
If the child process start function returns
ignore
, the child specification is added to the supervisor (unless the supervisor is asimple_one_for_one
supervisor, see below), the pid is set toundefined
, and the function returns{ok,undefined}
.子プロセスの start 関数が
ignore
を返した場合、子の仕様は supervisor に加えられるが pid はundefined
に設定され、(start_child
)関数は{ok, undefined}
を返す。
つまり、プロセスは起動させないが ChildSpec を登録するというようなことができる。
この影響で supervisor:child()
の型には pid()
だけでなく undefined
が含まれるので注意しなければならない。
ちなみに、 simple_one_for_one
の時は子の仕様は追加されない。
For a
simple_one_for_one
supervisor, when a child process start function returnsignore
, the functions returns{ok,undefined}
and no child is added to the supervisor.
simple_one_for_one
の supervisor においては、子プロセスの start 関数がignore
を返した時、(start_child
)関数は{ok, undefined}
を返し、子は supervisor に追加しない。
もちろん、 supervisor:start_link/2, 3
も ignore
を返せる。
ただ、めったに使うことがないと思われるので、皆さん ignore しておいてもいいのではないでしょうか。