From 54e510d909f1faa9b3d0999c1c26ac6660ce69da Mon Sep 17 00:00:00 2001 From: "eryn L. K" Date: Mon, 27 Dec 2021 22:41:42 -0500 Subject: [PATCH] Use task.spawn instead of BindableEvent for await --- lib/init.lua | 7 +++---- lib/init.spec.lua | 12 ++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) 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()