Skip to content

Incorrect assert in the example #13

@Egor-Skriptunoff

Description

@Egor-Skriptunoff

There is a pointless assert in the example of "beautiful asynchronous code":

   local co = assert(coroutine.running(), "Should be run in a coroutine")

Since Lua 5.2, the first value returned by coroutine.running() is always truthy.
Probably, the second returned value must be inspected instead of the first one?
Something like the following:

   local co, is_main = coroutine.running()
   assert(not is_main, "Should be run in a coroutine")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions