mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +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
|
||||
|
||||
- Add `finallyCall`, `andThenCall`
|
||||
|
|
|
@ -146,9 +146,6 @@ docs:
|
|||
type:
|
||||
kind: function
|
||||
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:
|
||||
- desc: The function acts like the passed function but now returns a Promise of its return values.
|
||||
type:
|
||||
|
|
|
@ -335,15 +335,11 @@ end
|
|||
--[[
|
||||
Converts a yielding function into a Promise-returning one.
|
||||
]]
|
||||
function Promise.promisify(callback, selfValue)
|
||||
function Promise.promisify(callback)
|
||||
return function(...)
|
||||
local length, values = pack(...)
|
||||
return Promise.new(function(resolve)
|
||||
if selfValue == nil then
|
||||
resolve(callback(unpack(values, 1, length)))
|
||||
else
|
||||
resolve(callback(selfValue, unpack(values, 1, length)))
|
||||
end
|
||||
resolve(coroutine.wrap(callback)(unpack(values, 1, length)))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue