Skip to content

v2.5.0

Compare
Choose a tag to compare
@timcassell timcassell released this 15 May 11:00
· 771 commits to master since this release

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) accepting CancelationToken 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, and Promise.SwitchToContextAwait for more efficient context switch in async 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 implementing IAwaitInstruction or IAwaitWithProgressInstruction.

Optimizations:

  • Promise(<T>).Canceled() now uses a singleton reference, instead of accessing the object pool/allocating.
  • Exposed Promise.Manager.ThreadStaticSynchronizationContext for efficient synchronous WaitAsync, 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 the SynchronizationContext.Current instead of UnitySynchronizationContext.
  • PromiseYielder.WaitOneFrame() no longer allocates and is faster (now 4x faster than yield 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). Use Promise.NewDeferred() and CancelationToken.Register to cancel the deferred directly.
  • deprecated Promise.Wait(int), Promise<T>.WaitForResult(int, out T), AsyncMonitor.WaitAsync(AsyncLock.Key, CancelationToken). Use methods with Try-prefixed of the same name.
  • deprecated PromiseYielder.WaitOneFrame(CancelationToken). Use PromiseYielder.WaitOneFrame() for the new optimized behavior, or PromiseYielder.WaitFor(null, CancelationToken) for the old behavior.

Breaking Changes:

  • PromiseYielder.WaitOneFrame() now returns WaitOneFrameAwaiter instead of Promise.
  • Unity Package Manager git url changed to https://github.com/TimCassell/ProtoPromise.git?path=Package (was https://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 throws CanceledException).
  • Promise(<T>).ResultContainer.Rethrow... now throws the actual exception instead of a RethrowException.

Misc:

  • Relaxed Promise(<T>).ResultContainer from readonly ref struct to readonly struct.
  • Exceptions from PromiseSynchronizationContext.Send are now wrapped in System.Exception and re-thrown in old runtime.
  • Various xml documentation fixes.