Revert to using BindableEvents for await

This commit is contained in:
Eryn Lynn 2018-11-09 03:40:40 -05:00
parent 601127071c
commit 154dc3cf9e

View file

@ -393,26 +393,26 @@ function Promise.prototype:await()
self._unhandledRejection = false self._unhandledRejection = false
if self._status == Promise.Status.Started then if self._status == Promise.Status.Started then
local ok, result, resultLength local result
local resultLength
local bindable = Instance.new("BindableEvent")
local thread = coroutine.running() self:andThen(
function(...)
spawn(function() resultLength, result = pack(...)
self:andThen( bindable:Fire(true)
function(...) end,
resultLength, result = pack(...) function(...)
ok = true resultLength, result = pack(...)
end, bindable:Fire(false)
function(...) end
resultLength, result = pack(...) )
ok = false self:finally(function()
end bindable:Fire(nil)
):finally(function()
coroutine.resume(thread)
end)
end) end)
coroutine.yield() local ok = bindable.Event:Wait()
bindable:Destroy()
if ok == nil then if ok == nil then
-- If cancelled, we return nil. -- If cancelled, we return nil.