mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +00:00
Add traceback piping to more functions
This commit is contained in:
parent
4ecdd156a5
commit
87937962ad
2 changed files with 10 additions and 10 deletions
|
@ -2,9 +2,9 @@
|
||||||
"name": "lua-promise",
|
"name": "lua-promise",
|
||||||
"tree": {
|
"tree": {
|
||||||
"$className": "DataModel",
|
"$className": "DataModel",
|
||||||
"ReplicatedStorage": {
|
"ServerScriptService": {
|
||||||
"$className": "ReplicatedStorage",
|
"$className": "ServerScriptService",
|
||||||
"Promise": {
|
"Lib": {
|
||||||
"$path": "lib"
|
"$path": "lib"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
lib/init.lua
14
lib/init.lua
|
@ -206,7 +206,7 @@ end
|
||||||
function Promise.async(callback)
|
function Promise.async(callback)
|
||||||
local traceback = debug.traceback()
|
local traceback = debug.traceback()
|
||||||
local promise
|
local promise
|
||||||
promise = Promise.new(function(resolve, reject, onCancel)
|
promise = Promise._new(traceback, function(resolve, reject, onCancel)
|
||||||
local connection
|
local connection
|
||||||
connection = RunService.Heartbeat:Connect(function()
|
connection = RunService.Heartbeat:Connect(function()
|
||||||
connection:Disconnect()
|
connection:Disconnect()
|
||||||
|
@ -227,7 +227,7 @@ end
|
||||||
]]
|
]]
|
||||||
function Promise.resolve(...)
|
function Promise.resolve(...)
|
||||||
local length, values = pack(...)
|
local length, values = pack(...)
|
||||||
return Promise.new(function(resolve)
|
return Promise._new(debug.traceback(), function(resolve)
|
||||||
resolve(unpack(values, 1, length))
|
resolve(unpack(values, 1, length))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -237,7 +237,7 @@ end
|
||||||
]]
|
]]
|
||||||
function Promise.reject(...)
|
function Promise.reject(...)
|
||||||
local length, values = pack(...)
|
local length, values = pack(...)
|
||||||
return Promise.new(function(_, reject)
|
return Promise._new(debug.traceback(), function(_, reject)
|
||||||
reject(unpack(values, 1, length))
|
reject(unpack(values, 1, length))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -377,7 +377,7 @@ function Promise.allSettled(promises)
|
||||||
return Promise.resolve({})
|
return Promise.resolve({})
|
||||||
end
|
end
|
||||||
|
|
||||||
return Promise.new(function(resolve, _, onCancel)
|
return Promise._new(debug.traceback(), function(resolve, _, onCancel)
|
||||||
-- An array to contain our resolved values from the given promises.
|
-- An array to contain our resolved values from the given promises.
|
||||||
local fates = {}
|
local fates = {}
|
||||||
local newPromises = {}
|
local newPromises = {}
|
||||||
|
@ -429,7 +429,7 @@ function Promise.race(promises)
|
||||||
assert(Promise.is(promise), (ERROR_NON_PROMISE_IN_LIST):format("Promise.race", tostring(i)))
|
assert(Promise.is(promise), (ERROR_NON_PROMISE_IN_LIST):format("Promise.race", tostring(i)))
|
||||||
end
|
end
|
||||||
|
|
||||||
return Promise.new(function(resolve, reject, onCancel)
|
return Promise._new(debug.traceback(), function(resolve, reject, onCancel)
|
||||||
local newPromises = {}
|
local newPromises = {}
|
||||||
local finished = false
|
local finished = false
|
||||||
|
|
||||||
|
@ -482,7 +482,7 @@ function Promise.promisify(callback)
|
||||||
return function(...)
|
return function(...)
|
||||||
local traceback = debug.traceback()
|
local traceback = debug.traceback()
|
||||||
local length, values = pack(...)
|
local length, values = pack(...)
|
||||||
return Promise.new(function(resolve, reject)
|
return Promise._new(traceback, function(resolve, reject)
|
||||||
coroutine.wrap(function()
|
coroutine.wrap(function()
|
||||||
local ok, resultLength, resultValues = packResult(pcall(callback, unpack(values, 1, length)))
|
local ok, resultLength, resultValues = packResult(pcall(callback, unpack(values, 1, length)))
|
||||||
if ok then
|
if ok then
|
||||||
|
@ -546,7 +546,7 @@ do
|
||||||
seconds = 0
|
seconds = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
return Promise.new(function(resolve, _, onCancel)
|
return Promise._new(debug.traceback(), function(resolve, _, onCancel)
|
||||||
enqueue(resolve, seconds)
|
enqueue(resolve, seconds)
|
||||||
|
|
||||||
onCancel(function()
|
onCancel(function()
|
||||||
|
|
Loading…
Reference in a new issue