diff --git a/lib/init.lua b/lib/init.lua index 98ceb40..4287997 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -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 diff --git a/lib/init.spec.lua b/lib/init.spec.lua index 5f0a936..047f281 100644 --- a/lib/init.spec.lua +++ b/lib/init.spec.lua @@ -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()