Skip to content

Instantly share code, notes, and snippets.

@lucasmz-dev
Last active December 2, 2021 00:30
Show Gist options
  • Save lucasmz-dev/65d3d3355803d351f6b78ce4094427d9 to your computer and use it in GitHub Desktop.
Save lucasmz-dev/65d3d3355803d351f6b78ce4094427d9 to your computer and use it in GitHub Desktop.
Exit implementation in Luau (task. required)
--[=[
A function which makes it so that the current thread is interrupted, and causes an error when on an attempt to resume it.
@yields
]=]
local function exit()
task.defer(
coroutine.close,
coroutine.running()
)
coroutine.yield()
error("Attempted to resume dead coroutine")
end
return exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment