mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +00:00
Make Promise.promisify use coroutine.wrap
This commit is contained in:
parent
9e40be2532
commit
8650aeffdb
3 changed files with 6 additions and 9 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
# 2.2.0
|
||||||
|
|
||||||
|
- `Promise.promisify` now uses `coroutine.wrap` instead of `Promise.spawn`
|
||||||
|
|
||||||
# 2.1.0
|
# 2.1.0
|
||||||
|
|
||||||
- Add `finallyCall`, `andThenCall`
|
- Add `finallyCall`, `andThenCall`
|
||||||
|
|
|
@ -146,9 +146,6 @@ docs:
|
||||||
type:
|
type:
|
||||||
kind: function
|
kind: function
|
||||||
params: "...: ...any?"
|
params: "...: ...any?"
|
||||||
- name: selfValue
|
|
||||||
type: any?
|
|
||||||
desc: This value will be prepended to the arguments list given to the curried function. This can be used to lock a method to a single instance. Otherwise, you can pass the self value before the argument list.
|
|
||||||
returns:
|
returns:
|
||||||
- desc: The function acts like the passed function but now returns a Promise of its return values.
|
- desc: The function acts like the passed function but now returns a Promise of its return values.
|
||||||
type:
|
type:
|
||||||
|
|
|
@ -335,15 +335,11 @@ end
|
||||||
--[[
|
--[[
|
||||||
Converts a yielding function into a Promise-returning one.
|
Converts a yielding function into a Promise-returning one.
|
||||||
]]
|
]]
|
||||||
function Promise.promisify(callback, selfValue)
|
function Promise.promisify(callback)
|
||||||
return function(...)
|
return function(...)
|
||||||
local length, values = pack(...)
|
local length, values = pack(...)
|
||||||
return Promise.new(function(resolve)
|
return Promise.new(function(resolve)
|
||||||
if selfValue == nil then
|
resolve(coroutine.wrap(callback)(unpack(values, 1, length)))
|
||||||
resolve(callback(unpack(values, 1, length)))
|
|
||||||
else
|
|
||||||
resolve(callback(selfValue, unpack(values, 1, length)))
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue