mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-25 08:00:03 +00:00
Revert back to Promise._timeEvent and Promise._getTime statics
This commit is contained in:
parent
d1ff9be774
commit
313d1cb6ab
1 changed files with 9 additions and 9 deletions
18
lib/init.lua
18
lib/init.lua
|
@ -5,8 +5,6 @@
|
||||||
local ERROR_NON_PROMISE_IN_LIST = "Non-promise value passed into %s at index %s"
|
local ERROR_NON_PROMISE_IN_LIST = "Non-promise value passed into %s at index %s"
|
||||||
local ERROR_NON_LIST = "Please pass a list of promises to %s"
|
local ERROR_NON_LIST = "Please pass a list of promises to %s"
|
||||||
local ERROR_NON_FUNCTION = "Please pass a handler function to %s!"
|
local ERROR_NON_FUNCTION = "Please pass a handler function to %s!"
|
||||||
local TIME_GETTER = os.clock
|
|
||||||
local TIME_EVENT = game:GetService("RunService").Heartbeat
|
|
||||||
local MODE_KEY_METATABLE = {__mode = "k"}
|
local MODE_KEY_METATABLE = {__mode = "k"}
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
@ -53,7 +51,7 @@ local Error do
|
||||||
context = options.context,
|
context = options.context,
|
||||||
kind = options.kind,
|
kind = options.kind,
|
||||||
parent = parent,
|
parent = parent,
|
||||||
createdTick = TIME_GETTER(),
|
createdTick = os.clock(),
|
||||||
createdTrace = debug.traceback(),
|
createdTrace = debug.traceback(),
|
||||||
}, Error)
|
}, Error)
|
||||||
end
|
end
|
||||||
|
@ -177,6 +175,8 @@ end
|
||||||
local Promise = {
|
local Promise = {
|
||||||
Error = Error,
|
Error = Error,
|
||||||
Status = makeEnum("Promise.Status", {"Started", "Resolved", "Rejected", "Cancelled"}),
|
Status = makeEnum("Promise.Status", {"Started", "Resolved", "Rejected", "Cancelled"}),
|
||||||
|
_getTime = os.clock,
|
||||||
|
_timeEvent = game:GetService("RunService").Heartbeat,
|
||||||
}
|
}
|
||||||
Promise.prototype = {}
|
Promise.prototype = {}
|
||||||
Promise.__index = Promise.prototype
|
Promise.__index = Promise.prototype
|
||||||
|
@ -291,7 +291,7 @@ function Promise.defer(callback)
|
||||||
local promise
|
local promise
|
||||||
promise = Promise._new(traceback, function(resolve, reject, onCancel)
|
promise = Promise._new(traceback, function(resolve, reject, onCancel)
|
||||||
local connection
|
local connection
|
||||||
connection = TIME_EVENT:Connect(function()
|
connection = Promise._timeEvent:Connect(function()
|
||||||
connection:Disconnect()
|
connection:Disconnect()
|
||||||
local ok, _, result = runExecutor(traceback, callback, resolve, reject, onCancel)
|
local ok, _, result = runExecutor(traceback, callback, resolve, reject, onCancel)
|
||||||
|
|
||||||
|
@ -703,7 +703,7 @@ do
|
||||||
end
|
end
|
||||||
|
|
||||||
return Promise._new(debug.traceback(nil, 2), function(resolve, _, onCancel)
|
return Promise._new(debug.traceback(nil, 2), function(resolve, _, onCancel)
|
||||||
local startTime = TIME_GETTER()
|
local startTime = Promise._getTime()
|
||||||
local endTime = startTime + seconds
|
local endTime = startTime + seconds
|
||||||
|
|
||||||
local node = {
|
local node = {
|
||||||
|
@ -714,8 +714,8 @@ do
|
||||||
|
|
||||||
if connection == nil then -- first is nil when connection is nil
|
if connection == nil then -- first is nil when connection is nil
|
||||||
first = node
|
first = node
|
||||||
connection = TIME_EVENT:Connect(function()
|
connection = Promise._timeEvent:Connect(function()
|
||||||
while first.endTime <= TIME_GETTER() do
|
while first.endTime <= Promise._getTime() do
|
||||||
local current = first
|
local current = first
|
||||||
first = current.next
|
first = current.next
|
||||||
|
|
||||||
|
@ -726,7 +726,7 @@ do
|
||||||
first.previous = nil
|
first.previous = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
current.resolve(TIME_GETTER() - current.startTime)
|
current.resolve(Promise._getTime() - current.startTime)
|
||||||
if current.next == nil then return end -- kill this thread if there was no `first` before `resolve`
|
if current.next == nil then return end -- kill this thread if there was no `first` before `resolve`
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -1248,7 +1248,7 @@ function Promise.prototype:_reject(...)
|
||||||
local err = tostring((...))
|
local err = tostring((...))
|
||||||
|
|
||||||
coroutine.wrap(function()
|
coroutine.wrap(function()
|
||||||
TIME_EVENT:Wait()
|
Promise._timeEvent:Wait()
|
||||||
|
|
||||||
-- Someone observed the error, hooray!
|
-- Someone observed the error, hooray!
|
||||||
if not self._unhandledRejection then
|
if not self._unhandledRejection then
|
||||||
|
|
Loading…
Reference in a new issue