lua-users home
lua-l archive

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


Thanks Sean, I always felt I had some greatness in me but you were the first one to recognize it.
(but then I saw your other answers 😶)

So, another question - is it theoretically possible to return a proxy (or decorator) object that behaves as an expected type upon access?
i.e. if "foo" returns a number, then we will return a custom c-object that behaves internally as a promise but upon any external access realizes it?



On Wed, Feb 22, 2023 at 7:28 AM Sean Conner <sean@conman.org> wrote:
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


--
Best regards,
     Roman