From 154dc3cf9ed71ed2da89054ab9056d22b513fc95 Mon Sep 17 00:00:00 2001 From: Eryn Lynn Date: Fri, 9 Nov 2018 03:40:40 -0500 Subject: [PATCH] Revert to using BindableEvents for await --- lib/init.lua | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index e6ceb72..de1a63b 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -393,26 +393,26 @@ function Promise.prototype:await() self._unhandledRejection = false if self._status == Promise.Status.Started then - local ok, result, resultLength + local result + local resultLength + local bindable = Instance.new("BindableEvent") - local thread = coroutine.running() - - spawn(function() - self:andThen( - function(...) - resultLength, result = pack(...) - ok = true - end, - function(...) - resultLength, result = pack(...) - ok = false - end - ):finally(function() - coroutine.resume(thread) - end) + self:andThen( + function(...) + resultLength, result = pack(...) + bindable:Fire(true) + end, + function(...) + resultLength, result = pack(...) + bindable:Fire(false) + end + ) + self:finally(function() + bindable:Fire(nil) end) - coroutine.yield() + local ok = bindable.Event:Wait() + bindable:Destroy() if ok == nil then -- If cancelled, we return nil.