11using System ;
2+ using System . Runtime . CompilerServices ;
23using System . Threading ;
34
45namespace UnityAsync
56{
67 public static partial class Await
78 {
9+ static readonly Continuation < WaitForFrames > nextUpdate = new Continuation < WaitForFrames > ( new WaitForFrames ( 1 ) ) ;
10+ static readonly Continuation < WaitForFrames > nextLateUpdate = new Continuation < WaitForFrames > ( new WaitForFrames ( 1 ) , FrameScheduler . LateUpdate ) ;
11+ static readonly Continuation < WaitForFrames > nextFixedUpdate = new Continuation < WaitForFrames > ( new WaitForFrames ( 1 ) , FrameScheduler . FixedUpdate ) ;
12+
813 /// <summary>
914 /// Quick access to Unity's <see cref="System.Threading.SynchronizationContext"/>.
1015 /// </summary>
16+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1117 public static SynchronizationContext UnitySyncContext ( ) => AsyncManager . UnitySyncContext ;
1218
1319 /// <summary>
1420 /// Quick access to the background <see cref="System.Threading.SynchronizationContext"/>.
1521 /// </summary>
22+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1623 public static SynchronizationContext BackgroundSyncContext ( ) => AsyncManager . BackgroundSyncContext ;
1724
1825 /// <summary>
1926 /// Convenience function to skip a single frame, equivalent to Unity's <c>yield return null</c>.
2027 /// </summary>
21- public static WaitForFrames NextUpdate ( ) => new WaitForFrames ( 1 ) ;
28+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
29+ public static Continuation < WaitForFrames > NextUpdate ( ) => nextUpdate ;
2230
2331 /// <summary>
2432 /// Convenience function to skip a number of frames, equivalent to multiple <c>yield return null</c>s.
2533 /// </summary>
26- public static WaitForFrames Updates ( int count ) => new WaitForFrames ( count ) ;
34+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
35+ public static Continuation < WaitForFrames > Updates ( int count ) => new Continuation < WaitForFrames > ( new WaitForFrames ( count ) ) ;
2736
2837 /// <summary>
2938 /// Convenience function to skip a single frame and continue in the LateUpdate loop.
3039 /// </summary>
31- public static Continuation < WaitForFrames > NextLateUpdate ( ) => new WaitForFrames ( 1 ) . ConfigureAwait ( FrameScheduler . LateUpdate ) ;
40+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
41+ public static Continuation < WaitForFrames > NextLateUpdate ( ) => nextLateUpdate ;
3242
3343 /// <summary>
3444 /// Convenience function to skip multiple frames and continue in the LateUpdate loop.
3545 /// </summary>
36- public static Continuation < WaitForFrames > LateUpdates ( int count ) => new WaitForFrames ( count ) . ConfigureAwait ( FrameScheduler . LateUpdate ) ;
46+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
47+ public static Continuation < WaitForFrames > LateUpdates ( int count ) => new Continuation < WaitForFrames > ( new WaitForFrames ( count ) , FrameScheduler . LateUpdate ) ;
3748
3849 /// <summary>
3950 /// Convenience function to skip a single FixedUpdate frame and continue in the FixedUpdate loop. Equivalent to
4051 /// Unity's <see cref="UnityEngine.WaitForFixedUpdate"/>.
4152 /// </summary>
42- public static Continuation < WaitForFrames > NextFixedUpdate ( ) => new WaitForFrames ( 1 ) . ConfigureAwait ( FrameScheduler . FixedUpdate ) ;
53+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
54+ public static Continuation < WaitForFrames > NextFixedUpdate ( ) => nextFixedUpdate ;
4355
4456 /// <summary>
4557 /// Convenience function to skip multiple FixedUpdate frames and continue in the FixedUpdate loop.
4658 /// </summary>
47- public static Continuation < WaitForFrames > FixedUpdates ( int count ) => new WaitForFrames ( count ) . ConfigureAwait ( FrameScheduler . FixedUpdate ) ;
59+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
60+ public static Continuation < WaitForFrames > FixedUpdates ( int count ) => new Continuation < WaitForFrames > ( new WaitForFrames ( count ) , FrameScheduler . FixedUpdate ) ;
4861
4962 /// <summary>
5063 /// Convenience function to wait for a number of in-game seconds before continuing, equivalent to Unity's
5164 /// <see cref="UnityEngine.WaitForSeconds"/>.
5265 /// </summary>
66+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5367 public static WaitForSeconds Seconds ( float duration ) => new WaitForSeconds ( duration ) ;
5468
5569 /// <summary>
5670 /// Convenience function to wait for a number of unscaled seconds before continuing. Equivalent to Unity's
5771 /// <see cref="UnityEngine.WaitForSecondsRealtime"/>.
5872 /// </summary>
73+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5974 public static WaitForSecondsRealtime SecondsRealtime ( float duration ) => new WaitForSecondsRealtime ( duration ) ;
6075
6176 /// <summary>
6277 /// Convenience function to wait for a condition to return true. Equivalent to Unity's
6378 /// <see cref="UnityEngine.WaitUntil"/>.
6479 /// </summary>
80+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
6581 public static WaitUntil Until ( Func < bool > condition ) => new WaitUntil ( condition ) ;
6682
6783 /// <summary>
6884 /// Convenience function to wait for a condition to return false. Equivalent to Unity's
6985 /// <see cref="UnityEngine.WaitWhile"/>.
7086 /// </summary>
87+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
7188 public static WaitWhile While ( Func < bool > condition ) => new WaitWhile ( condition ) ;
7289 }
7390}
0 commit comments