mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Remove status symbols
This commit is contained in:
parent
4829a421db
commit
f541fb7202
3 changed files with 23 additions and 19 deletions
|
@ -1,6 +1,10 @@
|
|||
# 2.4.1
|
||||
# Next
|
||||
|
||||
- Add Promise.tap
|
||||
- Fix bug with C functions not working when passed to andThen
|
||||
- Fix issue with Promise.race/all always cancelling instead of only cancelling if the Promise has no other consumers
|
||||
- Make error checking more robust across many methods.
|
||||
- Promise.Status members are now strings instead of symbols, and indexing a non-existent value will error.
|
||||
|
||||
# 2.4.0
|
||||
|
||||
|
|
28
lib/init.lua
28
lib/init.lua
|
@ -71,28 +71,20 @@ 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 = createSymbol("Started"),
|
||||
Resolved = createSymbol("Resolved"),
|
||||
Rejected = createSymbol("Rejected"),
|
||||
Cancelled = createSymbol("Cancelled"),
|
||||
}
|
||||
Promise.Status = setmetatable({
|
||||
Started = "Started",
|
||||
Resolved = "Resolved",
|
||||
Rejected = "Rejected",
|
||||
Cancelled = "Cancelled",
|
||||
}, {
|
||||
__index = function(_, k)
|
||||
error(("%s is not in Promise.Status!"):format(k), 2)
|
||||
end
|
||||
})
|
||||
|
||||
--[[
|
||||
Constructs a new Promise with the given initializing callback.
|
||||
|
|
|
@ -8,6 +8,14 @@ return function()
|
|||
return len, { ... }
|
||||
end
|
||||
|
||||
describe("Promise.Status", function()
|
||||
it("should error if indexing nil value", function()
|
||||
expect(function()
|
||||
local _ = Promise.Status.wrong
|
||||
end).to.throw()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("Promise.new", function()
|
||||
it("should instantiate with a callback", function()
|
||||
local promise = Promise.new(function() end)
|
||||
|
|
Loading…
Reference in a new issue