Use task.spawn instead of BindableEvent for await

This commit is contained in:
eryn L. K 2021-12-27 22:41:42 -05:00
parent 1fd66c87c9
commit 54e510d909
2 changed files with 15 additions and 4 deletions

View file

@ -1601,14 +1601,13 @@ function Promise.prototype:awaitStatus()
self._unhandledRejection = false
if self._status == Promise.Status.Started then
local bindable = Instance.new("BindableEvent")
local thread = coroutine.running()
self:finally(function()
bindable:Fire()
task.spawn(thread)
end)
bindable.Event:Wait()
bindable:Destroy()
coroutine.yield()
end
if self._status == Promise.Status.Resolved then

View file

@ -1362,6 +1362,18 @@ return function()
expect(d).to.equal(nil)
expect(e).to.equal(7)
end)
it("should work if yielding is needed", function()
local ran = false
task.spawn(function()
local _, actualTime = Promise.delay(1):await()
expect(type(actualTime)).to.equal("number")
ran = true
end)
advanceTime(2)
expect(ran).to.equal(true)
end)
end)
describe("Promise:expect", function()