- Added `any` type annotations to many variables in the internal implementation in order to prevent crashes while using this library
- Added `--!nonstrict` compiler directive at the top of the script to expose types
- Added library-user-facing typings for `Promise`, `Error`, `Status` and the library itself. This fork uses the `(object :: any) :: PublicType` idiom to simplify the types to the library, allowing for better autocompletion and type annotations in a strict-mode Luau codebase
No other changes have been made to the library's runtime behavior.
Please notify me through the issues section if any issues are encountered related to type safety or crashes. Otherwise, please send any issues related to runtime behavior to the [original repository](https://github.com/evaera/roblox-lua-promise).
-`Promise:finally` no longer observes a rejection from a Promise. Calling `Promise:finally` is mostly transparent now.
- The Promise returned by `Promise:finally` resolves or rejects with whatever the parent Promise resolved or rejected with. It will be cancelled if the parent Promise is cancelled.
- The value returned from the `finally` handler is discarded now.
- If the value returned from the `finally` handler is a Promise, we wait for it to resolve, but we do not use its value.
- If the value returned from the `finally` handler is a Promise and it rejects, `finally` returns the new rejected value.
-`Promise:finally` no longer counts as a consumer of the parent Promise for cancellation purposes. If all consumers are cancelled and the only remaining callbacks are finally handlers, the Promise is now cancelled.
- The Promise executor thread is now closed with `coroutine.close` when the Promise is cancelled.
- The Promise executor thread is now closed after the Promise settles (calling `resolve` or `reject`).
- Callbacks enqueued with `andThen` and `catch` are now dequeued if the Promise returned by `andThen`/`catch` is cancelled.
- Calling `andThen` or `catch` on an already-cancelled Promise now returns a cancelled Promise instead of returning a rejected Promise
-`:await`, `:expect`, and `:awaitStatus` are no longer backed by BindableEvents, and now use the task library directly, so performance should be better.
-`Promise:finally` no longer observes a rejection from a Promise. Calling `Promise:finally` is mostly transparent now.
- The Promise returned by `Promise:finally` resolves or rejects with whatever the parent Promise resolved or rejected with. It will be cancelled if the parent Promise is cancelled.
- The value returned from the `finally` handler is discarded now.
- If the value returned from the `finally` handler is a Promise, we wait for it to resolve, but we do not use its value.
- If the value returned from the `finally` handler is a Promise and it rejects, `finally` returns the new rejected value.
-`Promise:finally` no longer counts as a consumer of the parent Promise for cancellation purposes. If all consumers are cancelled and the only remaining callbacks are finally handlers, the Promise is now cancelled.
- The Promise executor thread is now closed with `coroutine.close` when the Promise is cancelled.
- The Promise executor thread is now closed after the Promise settles (calling `resolve` or `reject`).
- Callbacks enqueued with `andThen` and `catch` are now dequeued if the Promise returned by `andThen`/`catch` is cancelled.
- Calling `andThen` or `catch` on an already-cancelled Promise now returns a cancelled Promise instead of returning a rejected Promise
-`:await`, `:expect`, and `:awaitStatus` are no longer backed by BindableEvents, and now use the task library directly, so performance should be better.
### Removed
-`Promise:done` and its associated members have been removed.
- Runtime errors are now represented by objects. You must call tostring on rejection values before assuming they are strings (this was always good practice, but is required now).
- Yielding is now allowed in `Promise.new`, `andThen`, and `Promise.try` executors.
- Errors now have much better stack traces due to using `xpcall` internally instead of `pcall`.
- Stack traces will now be more direct and not include as many internal calls within the Promise library.
- Chained promises from `resolve()` or returning from andThen now have improved rejection messages for debugging.
-`Promise.async` has been renamed to `Promise.defer` (`Promise.async` references same function for compatibility)
- Promises now have a `__tostring` metamethod, which returns `Promise(Resolved)` or whatever the current status is.
-`Promise:timeout()` now rejects with a `Promise.Error(Promise.Error.Kind.TimedOut)` object. (Formerly rejected with the string `"Timed out"`)
- Attaching a handler to a cancelled Promise now rejects with a `Promise.Error(Promise.Error.Kind.AlreadyCancelled)`. (Formerly rejected with the string `"Promise is cancelled"`)
- Improved test coverage for asynchronous and time-driven functions
### Fixed
- Changed `Promise.is` to be safe when dealing with tables that have an `__index` metamethod that creates an error.
-`Promise.delay` resolve value (time passed) is now more accurate (previously passed time based on when we started resuming threads instead of the current time. This is a very minor difference.)