mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +00:00
Use task.spawn instead of BindableEvent for await
This commit is contained in:
parent
1fd66c87c9
commit
54e510d909
2 changed files with 15 additions and 4 deletions
|
@ -1601,14 +1601,13 @@ function Promise.prototype:awaitStatus()
|
||||||
self._unhandledRejection = false
|
self._unhandledRejection = false
|
||||||
|
|
||||||
if self._status == Promise.Status.Started then
|
if self._status == Promise.Status.Started then
|
||||||
local bindable = Instance.new("BindableEvent")
|
local thread = coroutine.running()
|
||||||
|
|
||||||
self:finally(function()
|
self:finally(function()
|
||||||
bindable:Fire()
|
task.spawn(thread)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
bindable.Event:Wait()
|
coroutine.yield()
|
||||||
bindable:Destroy()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if self._status == Promise.Status.Resolved then
|
if self._status == Promise.Status.Resolved then
|
||||||
|
|
|
@ -1362,6 +1362,18 @@ return function()
|
||||||
expect(d).to.equal(nil)
|
expect(d).to.equal(nil)
|
||||||
expect(e).to.equal(7)
|
expect(e).to.equal(7)
|
||||||
end)
|
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)
|
end)
|
||||||
|
|
||||||
describe("Promise:expect", function()
|
describe("Promise:expect", function()
|
||||||
|
|
Loading…
Reference in a new issue