lua-coronest icon indicating copy to clipboard operation
lua-coronest copied to clipboard

String tags with cache

Open mnemnion opened this issue 3 years ago • 0 comments

This changes the library so that string tags are auto-converted into a private table, and so that the return coroutine table is cached by tag.

The combination means that a user can get a consistent set of nested coroutine tools by string, from any module:

local coro = coromake 'scheduler'

Will return the same coro for any unique string, without causing trouble if that string is yielded by this or another yield function.

The alternative in the original code would involve either making global or passing around, some common table used only for this purpose, or choosing some metatable or function deemed unlikely to be used, and hoping we don't forget.

The original code also allows a string argument, but then will exhibit strange behavior if that string is yielded, ever, and that's the sort of bug no one wants to have. The semantics are unchanged if the argument isn't a string, and I would argue that what this patch does with strings is safer and more convenient.

mnemnion avatar Mar 26 '22 13:03 mnemnion