lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Roman Gershman once stated:
> Hello,
> 
> I need to implement a custom lua function that unfortunately has some
> latency - say, it reads from disk and returns the data:
> 
> With a single call it's bearable but if there is a script like
> ```
> foo();
> foo();
> foo();
> ```
> 
> then the latency multiplies. Is it possible to recognize that a caller does
> not really read foo's return value in the script?
> The motivation - to batch I/O requests together in that case by returning
> from the function earlier than the I/O finishes

  In general, no, it's not possible for foo() to know that its return value
is ignored.  Yes, it is possible to batch I/O requests and have them run in
the background, but no, it's not portable.  And there are different ways to
achieve what you want (threads doing the I/O or event driven I/O).

  -spc