在上一篇Elixir IO内幕(一)读操作中,我们看到了Elixir是怎么实现读IO的。那么这次就来看看怎么写IO。
写IO其实比读要简单,因为它只有下面几种消息:
{:io_request, sender_pid, reference, {:put_chars, chars}}
{:io_request, sender_pid, reference, {:put_chars, encoding, chars}}
{:io_request, sender_pid, reference, {:put_chars, mod, func, args}}
{:io_request, sender_pid, reference, {:put_chars, encoding, mod, func, args}}
后两种还是不知道对应什么,但是前两种对应啥应该不用我说了吧?
而且写操作的正常回复只有两种:
{:io_reply, reference, :ok}
{:io_reply, reference, {:error, reason}}
不用多写了吧?