mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Fix Promise.promisify and add test
This commit is contained in:
parent
8650aeffdb
commit
0139ed512f
2 changed files with 17 additions and 1 deletions
|
@ -339,7 +339,9 @@ function Promise.promisify(callback)
|
|||
return function(...)
|
||||
local length, values = pack(...)
|
||||
return Promise.new(function(resolve)
|
||||
resolve(coroutine.wrap(callback)(unpack(values, 1, length)))
|
||||
coroutine.wrap(function()
|
||||
resolve(callback(unpack(values, 1, length)))
|
||||
end)()
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -582,4 +582,18 @@ return function()
|
|||
expect(promises[2]:getStatus()).to.equal(Promise.Status.Resolved)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("Promise.promisify", function()
|
||||
it("should wrap functions", function()
|
||||
local function test(n)
|
||||
return n + 1
|
||||
end
|
||||
|
||||
local promisified = Promise.promisify(test)
|
||||
local status, result = promisified(1):awaitStatus()
|
||||
|
||||
expect(status).to.equal(Promise.Status.Resolved)
|
||||
expect(result).to.equal(2)
|
||||
end)
|
||||
end)
|
||||
end
|
Loading…
Reference in a new issue