diff --git a/CHANGELOG.md b/CHANGELOG.md index ec6d5a6..2975113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/init.lua b/lib/init.lua index 12a5546..8c41c42 100644 --- a/lib/init.lua +++ b/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. diff --git a/lib/init.spec.lua b/lib/init.spec.lua index 36611c1..e33aa01 100644 --- a/lib/init.spec.lua +++ b/lib/init.spec.lua @@ -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)