v2.0.0
Enhancements:
- Full library thread-safety with minimal locks.
- Added
Deferred.Cancel
. - Added
Deferred
andCancelationSource
andCancelationToken
andCancelationRegistration
Try...
methods. - Added
CancelationRegistration
methods to unregister/check registration and if the token is requesting cancelation atomically. - Added static
CancelationToken.Canceled()
to get a token already in the canceled state without allocating. - Added
Promise(<T>).WaitAsync(SynchronizationOption)
andPromise(<T>).WaitAsync(SynchronizationContext)
to schedule the next callback/await on the desired context. - Added
Promise.Run
static functions. - Added
Promise.SwitchToForeground()
,Promise.SwitchToBackground()
, andPromise.SwitchToContext(SynchronizationContext)
static functions. - Added
Promise.AwaitWithProgress(float minProgress, float maxProgress)
API to propagate the progress to anasync Promise(<T>)
function.
Optimizations:
- Promises are now structs, making already resolved promises live only on the stack, increasing performance.
- Eliminated potential
StackOverflowException
s fromasync
/await
continuations when both theasync
function and theawait
ed object arePromise(<T>)
. - Optimized
async Promise(<T>)
functions in Unity 2021.2 or newer when IL2CPP is used.
Breaking Changes:
- Promises are now structs instead of classes.
- Changed behavior of
Promise.CatchCancelation
to return a new promise and behave more likePromise.Catch
, whereonCanceled
resolves the returned promise when it returns, or adopts the state of the returned promise. - Removed cancelation reasons.
- A rejected promise awaited in an async function now throws the original exception, if the promise was rejected with an exception.
- Deprecations and other breaking changes (see full release notes).
See Release Notes for the full changelog.