Re: data, err = f() idiom
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: data, err = f() idiom
- From: Rebel Neurofog <rebelneurofog@...>
- Date: 2012年1月19日 16:17:58 +0300
> When writing:
>
> local data, err = f()
>
> what is the error condition, data being nil, or err being not nil?
data being nil or false
> Is returning data AND a error frowned upon? Example: your f() is
> instructed to return data in chunks of N bytes. But when the last chunk
> is being read, the connection (socket, whatever) closes and f has less
> than N bytes. An API that returns "incompletedata, 'closed'" is well
> regarded?
>
-- You may consider following:
local status, data = assert (f ())
-- or even
local data, status = assert (f ()) -- here data should be "" in case
of "incompletedata" or "closed"