Make Promise.promisify use coroutine.wrap

This commit is contained in:
Eryn Lynn 2019-09-13 22:58:32 -04:00
parent 9e40be2532
commit 8650aeffdb
3 changed files with 6 additions and 9 deletions

View file

@ -1,3 +1,7 @@
# 2.2.0
- `Promise.promisify` now uses `coroutine.wrap` instead of `Promise.spawn`
# 2.1.0
- Add `finallyCall`, `andThenCall`

View file

@ -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:

View file

@ -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