mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +00:00
parent
c0626c0baf
commit
f6c3dd163a
3 changed files with 14 additions and 10 deletions
|
@ -163,13 +163,13 @@ docs:
|
||||||
- name: resolve
|
- name: resolve
|
||||||
desc: Creates an immediately resolved Promise with the given value.
|
desc: Creates an immediately resolved Promise with the given value.
|
||||||
static: true
|
static: true
|
||||||
params: "value: T"
|
params: "value: ...any"
|
||||||
returns: Promise<T>
|
returns: Promise<...any>
|
||||||
- name: reject
|
- name: reject
|
||||||
desc: Creates an immediately rejected Promise with the given value.
|
desc: Creates an immediately rejected Promise with the given value.
|
||||||
static: true
|
static: true
|
||||||
params: "value: T"
|
params: "value: ...any"
|
||||||
returns: Promise<T>
|
returns: Promise<...any>
|
||||||
- name: all
|
- name: all
|
||||||
desc: |
|
desc: |
|
||||||
Accepts an array of Promises and returns a new promise that:
|
Accepts an array of Promises and returns a new promise that:
|
||||||
|
|
10
lib/init.lua
10
lib/init.lua
|
@ -230,18 +230,20 @@ end
|
||||||
--[[
|
--[[
|
||||||
Create a promise that represents the immediately resolved value.
|
Create a promise that represents the immediately resolved value.
|
||||||
]]
|
]]
|
||||||
function Promise.resolve(value)
|
function Promise.resolve(...)
|
||||||
|
local length, values = pack(...)
|
||||||
return Promise.new(function(resolve)
|
return Promise.new(function(resolve)
|
||||||
resolve(value)
|
resolve(unpack(values, 1, length))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Create a promise that represents the immediately rejected value.
|
Create a promise that represents the immediately rejected value.
|
||||||
]]
|
]]
|
||||||
function Promise.reject(value)
|
function Promise.reject(...)
|
||||||
|
local length, values = pack(...)
|
||||||
return Promise.new(function(_, reject)
|
return Promise.new(function(_, reject)
|
||||||
reject(value)
|
reject(unpack(values, 1, length))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -90,11 +90,12 @@ return function()
|
||||||
|
|
||||||
describe("Promise.resolve", function()
|
describe("Promise.resolve", function()
|
||||||
it("should immediately resolve with a value", function()
|
it("should immediately resolve with a value", function()
|
||||||
local promise = Promise.resolve(5)
|
local promise = Promise.resolve(5, 6)
|
||||||
|
|
||||||
expect(promise).to.be.ok()
|
expect(promise).to.be.ok()
|
||||||
expect(promise:getStatus()).to.equal(Promise.Status.Resolved)
|
expect(promise:getStatus()).to.equal(Promise.Status.Resolved)
|
||||||
expect(promise._values[1]).to.equal(5)
|
expect(promise._values[1]).to.equal(5)
|
||||||
|
expect(promise._values[2]).to.equal(6)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should chain onto passed promises", function()
|
it("should chain onto passed promises", function()
|
||||||
|
@ -110,11 +111,12 @@ return function()
|
||||||
|
|
||||||
describe("Promise.reject", function()
|
describe("Promise.reject", function()
|
||||||
it("should immediately reject with a value", function()
|
it("should immediately reject with a value", function()
|
||||||
local promise = Promise.reject(6)
|
local promise = Promise.reject(6, 7)
|
||||||
|
|
||||||
expect(promise).to.be.ok()
|
expect(promise).to.be.ok()
|
||||||
expect(promise:getStatus()).to.equal(Promise.Status.Rejected)
|
expect(promise:getStatus()).to.equal(Promise.Status.Rejected)
|
||||||
expect(promise._values[1]).to.equal(6)
|
expect(promise._values[1]).to.equal(6)
|
||||||
|
expect(promise._values[2]).to.equal(7)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should pass a promise as-is as an error", function()
|
it("should pass a promise as-is as an error", function()
|
||||||
|
|
Loading…
Reference in a new issue