mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +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
|
||||
|
||||
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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue