On Oct 31, 2014, at 11:22 AM, Tim Caswell <[email protected]> wrote:
> I think that callback support can easily be integrated into the existing > callback APIs. Here is an example of an API that supports both blocking and > non-blocking syntax. If you leave out the callback and are in a coroutine, > it will suspend the coroutine while blocking on the I/O. The internal code > can still do things in parallel with callbacks, but the external API is nice > and sync. > > https://github.com/luvit/luvit/blob/c83252fcf2b085fb9c272425b008a829fe6879ec/test-tls.lua#L276-L299 Here's a fan of the coroutine-based sync style (of course). > Integration with a callback API simply requires a new line at the top at the > bottom and callback internally replaced with `next`. > > https://github.com/luvit/luvit/blob/c83252fcf2b085fb9c272425b008a829fe6879ec/test-tls.lua#L50-L71 Shouldn’t onAddress and onConnect be local? Also since “next” is a built-in function in Lua, it might be better to use a different name to avoid the possibility of hard-to-understand bugs in the future. -- You received this message because you are subscribed to the Google Groups "luvit" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
