v2.5.0
Enhancements:
- Added
AsyncLazy
type. - Added more async synchronization primitives in the
Proto.Promises.Threading
namespace:AsyncReaderWriterLock
AsyncManualResetEvent
AsyncAutoResetEvent
AsyncSemaphore
AsyncCountdownEvent
AsyncConditionVariable
- Added
AsyncMonitor.TryEnter(Async)
acceptingCancelationToken
parameter. - Added APIs to wait for promise result without throwing. These get the result wrapped in
Promise(<T>).ResultContainer
, instead of throwing if the promise was rejected or canceled.Promise(<T>).AwaitNoThrow()
Promise(<T>).AwaitWithProgressNoThrow()
.Promise.(Try)WaitNoThrow
Promise<T>.(Try)WaitForResultNoThrow
.
- Added
Promise(<T>).ResultContainer.RethrowIfRejectedOrCanceled
. - Added
Promise.SwitchToForegroundAwait
,Promise.SwitchToBackgroundAwait
, andPromise.SwitchToContextAwait
for more efficient context switch inasync
functions. - Added common Unity awaits in
PromiseYielder
:PromiseYielder.WaitForFrames(uint)
PromiseYielder.WaitForTime(TimeSpan)
PromiseYielder.WaitForRealTime(TimeSpan)
PromiseYielder.WaitUntil(Func<bool>)
PromiseYielder.WaitUntil<TCapture>(TCapture, Func<TCapture, bool>)
PromiseYielder.WaitWhile(Func<bool>)
PromiseYielder.WaitWhile<TCapture>(TCapture, Func<TCapture, bool>)
PromiseYielder.WaitForAsyncOperation(AsyncOperation)
PromiseYielder.WaitForEndOfFrame()
PromiseYielder.WaitForFixedUpdate()
- Create custom
await
instructions in Unity by implementingIAwaitInstruction
orIAwaitWithProgressInstruction
.
Optimizations:
Promise(<T>).Canceled()
now uses a singleton reference, instead of accessing the object pool/allocating.- Exposed
Promise.Manager.ThreadStaticSynchronizationContext
for efficient synchronousWaitAsync
, etc calls. - Fixed a progress performance degradation when an uncommon race condition occurs.
- Optimized the common case in progress reports.
- In Unity,
PromiseSynchronizationContext
is set to theSynchronizationContext.Current
instead ofUnitySynchronizationContext
. PromiseYielder.WaitOneFrame()
no longer allocates and is faster (now 4x faster thanyield return null
).
Fixes:
- Fixed
Promise.All/Merge
progress when a promise is canceled. - Domain reload disabled in Unity Editor is now supported.
Deprecated:
- deprecated
Promise.NewDeferred(CancelationToken)
. UsePromise.NewDeferred()
andCancelationToken.Register
to cancel the deferred directly. - deprecated
Promise.Wait(int)
,Promise<T>.WaitForResult(int, out T)
,AsyncMonitor.WaitAsync(AsyncLock.Key, CancelationToken)
. Use methods withTry
-prefixed of the same name. - deprecated
PromiseYielder.WaitOneFrame(CancelationToken)
. UsePromiseYielder.WaitOneFrame()
for the new optimized behavior, orPromiseYielder.WaitFor(null, CancelationToken)
for the old behavior.
Breaking Changes:
PromiseYielder.WaitOneFrame()
now returnsWaitOneFrameAwaiter
instead ofPromise
.- Unity Package Manager git url changed to
https://github.com/TimCassell/ProtoPromise.git?path=Package
(washttps://github.com/TimCassell/ProtoPromise.git?path=ProtoPromise_Unity/Assets/Plugins/ProtoPromise
).
Minor Changes:
AsyncLock.LockAsync(CancelationToken)
returns a canceled promise if the token is already canceled (and the synchronous version throwsCanceledException
).Promise(<T>).ResultContainer.Rethrow...
now throws the actual exception instead of aRethrowException
.
Misc:
- Relaxed
Promise(<T>).ResultContainer
fromreadonly ref struct
toreadonly struct
. - Exceptions from
PromiseSynchronizationContext.Send
are now wrapped inSystem.Exception
and re-thrown in old runtime. - Various xml documentation fixes.