- [Prefer calling string functions directly](https://developer.roblox.com/en-us/resources/release-note/Release-Notes-for-433)
- Fixed spaces being used in `Promise.retry`.
- Fixed `Promise:done` calling itself `Promise:finallyO` in the assert. (intentional?)
- Prefer using the first return of `ipairs` to add a Promise to the array instead of `table.insert`.
- Removed the unused `reject` in `Promise._try`
- Trailing commas as per Roblox Lua style guide.
Other suggestions:
- You could use `table.create` in `Promise:timeout` like so:
```Lua
function Promise.prototype:timeout(seconds, rejectionValue)
local traceback = debug.traceback(nil, 2)
local racedPromises = table.create(2)
racedPromises[1] = Promise.delay(seconds):andThen(function()
return Promise.reject(rejectionValue == nil and Error.new({
kind = Error.Kind.TimedOut,
error = "Timed out",
context = string.format(
"Timeout of %d seconds exceeded.\n:timeout() called at:\n\n%s",
seconds,
traceback
),
}) or rejectionValue)
end)
racedPromises[2] = self
return Promise.race(racedPromises)
end
```
- Always iterate over promises via `ipairs`
- Avoid pushing the call arguments stack to a table in Promise.prototype.expect and Promise.prototype.await
- Use a doubly-linked list implementation of a queue
The old queue/dequeue implementation used an array which:
- has items removed from the front (`table.remove(queue, 1)` O(n) each time)
- this is especially bad in the main loop which could run multiple times in-a-row on a large array
- new: O(1)
- uses table.insert() followed by table.sort() to add a new node (O(n log n))
- new: O(n)
- has to lookup the index of the node being dequeued (O(n))
- new: O(1)