"tenderlovemaking (Aaron Patterson)" <aaron / tenderlovemaking.com> wrote:
> As for Erlang style return values.  It seems interesting, but that
> means every call to `try_read_nonblock` would allocate an array.  The
> only possible return values would be:

I prefer to avoid the requirement for allocating _anything_ in the
common case.  So "no" to the tuple retvals.

How about making the destination buffer a required argument,
and returning:

	Integer           - length in bytes on successful read
	Symbol            - :wait_readable/:wait_writable (common)
	nil               - EOF

  case ret = io.try_read(maxlen, buffer)
  when Integer
    process_buffer(buffer, ret)
  when nil
    break
  when Symbol
    io.__send__(ret, timeout_sec) # :wait_readable,:wait_writable
  end while true

I think making the buffer a required argument makes sense anyways for
performance (not just GC, but keeping the CPU cache hot regardless of
VM/language, too).