evaera / roblox-lua-promise

Promise implementation for Roblox
https://eryn.io/roblox-lua-promise/
MIT License
275 stars 74 forks source link

`Promise.defer` should use `task.defer` #88

Closed ghost closed 1 year ago

ghost commented 1 year ago

Currently, Promise.defer uses RunService.Heartbeat, which should be replaced with task.defer instead. The current implementation of Promise.defer results in the Promise being resumed in the next frame, rather than the next invocation point.

evaera commented 1 year ago

Why?

ghost commented 1 year ago

Why?

I think task.defer is better suited for what Promise.defer needs to accomplish -- the point is to simply resume a Promise as soon as possible, but not immediately, so resuming in the next frame when you can resume within the next invocation point (now) doesn't seem reasonable.

Hexcede commented 1 year ago

Why?

Here's a few reasons:

One thing to consider:


P.s. task.defer like all of the other task methods additionally works with threads, so the following is a sufficient replacement for a :Wait():

task.defer(coroutine.running())
coroutine.yield()