mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Convert Promise.Status to be a userdata with __tostring
This commit is contained in:
parent
8dd394cccd
commit
d8c3bb9264
1 changed files with 15 additions and 3 deletions
18
lib/init.lua
18
lib/init.lua
|
@ -62,14 +62,26 @@ local function isEmpty(t)
|
|||
return next(t) == nil
|
||||
end
|
||||
|
||||
local function createSymbol(name)
|
||||
assert(type(name) == "string", "createSymbol requires `name` to be a string.")
|
||||
|
||||
local symbol = newproxy(true)
|
||||
|
||||
getmetatable(symbol).__tostring = function()
|
||||
return ("Symbol(%s)"):format(name)
|
||||
end
|
||||
|
||||
return symbol
|
||||
end
|
||||
|
||||
local Promise = {}
|
||||
Promise.prototype = {}
|
||||
Promise.__index = Promise.prototype
|
||||
|
||||
Promise.Status = {
|
||||
Started = "Started",
|
||||
Resolved = "Resolved",
|
||||
Rejected = "Rejected",
|
||||
Started = createSymbol("Started"),
|
||||
Resolved = createSymbol("Resolved"),
|
||||
Rejected = createSymbol("Rejected"),
|
||||
}
|
||||
|
||||
--[[
|
||||
|
|
Loading…
Reference in a new issue