Literally every place I use it I want instead:
local function thisThread(): thread
return coroutine.running() or error("Must be called from a coroutine")
end
in base luau,
coroutine.running()
never returns nil, or at least, it's typed not to. I had to change the type because harold made it return nil sometimes, and I hate it.
I have no idea what kind of code is easier to write because it can return nil, but it's not my code. Every time I use it, I want to do something like:
function SocketClass.waitUntilClosed(self: Socket)
table.insert(self.onCloseAwaiting, coroutine.running())
coroutine.yield()
end
but, inserting nil into the table is definitely not what I want to do. nor is proceeding silently. it's programmer error to call async code without a coroutine, and that's what
error()
is for
In my mind, in a proper script, everything outside module scope is in a coroutine.