mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +00:00
Formatting and comment wrapping
This commit is contained in:
parent
d8c3bb9264
commit
639f0e8419
2 changed files with 10 additions and 8 deletions
16
lib/init.lua
16
lib/init.lua
|
@ -19,7 +19,7 @@ end
|
||||||
wpcallPacked is a version of xpcall that:
|
wpcallPacked is a version of xpcall that:
|
||||||
* Returns the length of the result first
|
* Returns the length of the result first
|
||||||
* Returns the result packed into a table
|
* Returns the result packed into a table
|
||||||
* Passes extra arguments through to the passed function, which xpcall does not
|
* Passes extra arguments through to the passed function; xpcall doesn't
|
||||||
* Issues a warning if PROMISE_DEBUG is enabled
|
* Issues a warning if PROMISE_DEBUG is enabled
|
||||||
]]
|
]]
|
||||||
local function wpcallPacked(f, ...)
|
local function wpcallPacked(f, ...)
|
||||||
|
@ -188,8 +188,8 @@ function Promise.all(promises)
|
||||||
return Promise.resolve({})
|
return Promise.resolve({})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- We need to check that each value is a promise here so that we can produce a
|
-- We need to check that each value is a promise here so that we can produce
|
||||||
-- proper error rather than a rejected promise with our error.
|
-- a proper error rather than a rejected promise with our error.
|
||||||
for i = 1, #promises do
|
for i = 1, #promises do
|
||||||
if not Promise.is(promises[i]) then
|
if not Promise.is(promises[i]) then
|
||||||
error(("Non-promise value passed into Promise.all at index #%d"):format(i), 2)
|
error(("Non-promise value passed into Promise.all at index #%d"):format(i), 2)
|
||||||
|
@ -199,8 +199,9 @@ function Promise.all(promises)
|
||||||
return Promise.new(function(resolve, reject)
|
return Promise.new(function(resolve, reject)
|
||||||
-- An array to contain our resolved values from the given promises.
|
-- An array to contain our resolved values from the given promises.
|
||||||
local resolvedValues = {}
|
local resolvedValues = {}
|
||||||
-- Keep a count of resolved promises because just checking the resolved values length
|
|
||||||
-- wouldn't account for promises that resolve with nil.
|
-- Keep a count of resolved promises because just checking the resolved
|
||||||
|
-- values length wouldn't account for promises that resolve with nil.
|
||||||
local resolvedCount = 0
|
local resolvedCount = 0
|
||||||
local rejected = false
|
local rejected = false
|
||||||
|
|
||||||
|
@ -219,7 +220,8 @@ function Promise.all(promises)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- We can assume the values inside `promises` are all promises since we checked above.
|
-- We can assume the values inside `promises` are all promises since we
|
||||||
|
-- checked above.
|
||||||
for i = 1, #promises do
|
for i = 1, #promises do
|
||||||
promises[i]:andThen(
|
promises[i]:andThen(
|
||||||
function(...)
|
function(...)
|
||||||
|
@ -424,4 +426,4 @@ function Promise.prototype:_reject(...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return Promise
|
return Promise
|
|
@ -389,4 +389,4 @@ return function()
|
||||||
expect(second).to.equal("qux")
|
expect(second).to.equal("qux")
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
Loading…
Reference in a new issue