mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +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
|
- 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
|
# 2.4.0
|
||||||
|
|
||||||
|
|
28
lib/init.lua
28
lib/init.lua
|
@ -71,28 +71,20 @@ local function isEmpty(t)
|
||||||
return next(t) == nil
|
return next(t) == nil
|
||||||
end
|
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 = {}
|
local Promise = {}
|
||||||
Promise.prototype = {}
|
Promise.prototype = {}
|
||||||
Promise.__index = Promise.prototype
|
Promise.__index = Promise.prototype
|
||||||
|
|
||||||
Promise.Status = {
|
Promise.Status = setmetatable({
|
||||||
Started = createSymbol("Started"),
|
Started = "Started",
|
||||||
Resolved = createSymbol("Resolved"),
|
Resolved = "Resolved",
|
||||||
Rejected = createSymbol("Rejected"),
|
Rejected = "Rejected",
|
||||||
Cancelled = createSymbol("Cancelled"),
|
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.
|
Constructs a new Promise with the given initializing callback.
|
||||||
|
|
|
@ -8,6 +8,14 @@ return function()
|
||||||
return len, { ... }
|
return len, { ... }
|
||||||
end
|
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()
|
describe("Promise.new", function()
|
||||||
it("should instantiate with a callback", function()
|
it("should instantiate with a callback", function()
|
||||||
local promise = Promise.new(function() end)
|
local promise = Promise.new(function() end)
|
||||||
|
|
Loading…
Reference in a new issue