@@ -23,24 +23,24 @@ private static void Install()
2323 UnitySynchronizationContext = SynchronizationContext . Current ;
2424 Application . quitting += OnApplicationQuitting ;
2525 }
26-
26+
2727#if UNITY_EDITOR
2828 [ InitializeOnLoadMethod ]
2929 private static void EditorInstall ( )
3030 {
31- EditorApplication . playModeStateChanged += EditorApplicationOnPlayModeStateChanged ;
31+ EditorApplication . playModeStateChanged += EditorApplicationOnPlayModeStateChanged ;
3232 }
3333
3434 private static void EditorApplicationOnPlayModeStateChanged ( PlayModeStateChange obj )
3535 {
3636 //I do not intend to support editor coroutines
3737 //Do I need to cancel coroutines on play mode change?
3838 }
39- #endif
40-
39+ #endif
40+
4141 private static SynchronizationContext UnitySynchronizationContext { get ; set ; }
4242 private static CancellationTokenSource cancellationTokenSource = new CancellationTokenSource ( ) ;
43-
43+
4444 /// <summary>
4545 /// Use this method when you want to await coroutine completion.
4646 /// Coroutine itself will always run on the main thread.
@@ -49,19 +49,19 @@ private static void EditorApplicationOnPlayModeStateChanged(PlayModeStateChange
4949 /// <returns>awaitable task</returns>
5050 public static async Task RunAsync ( IEnumerator routine )
5151 {
52- await UnityTaskUtil . RunOnUnityThreadAsync ( async ( ) => await RunAsync ( routine , cancellationTokenSource . Token ) . ConfigureAwait ( false ) ) ;
52+ await UnityTaskUtil . RunOnUnityThreadAsync ( async ( ) => await RunAsync ( routine , cancellationTokenSource . Token ) ) ;
5353 }
54-
54+
5555 /// <summary>
5656 /// Use this method to start a coroutine from any thread.
5757 /// Coroutines themselves always run on the main thread
5858 /// </summary>
5959 /// <param name="enumerator">coroutine to run</param>
6060 public static void Start ( IEnumerator enumerator )
6161 {
62- UnityTaskUtil . RunOnUnityThread ( async ( ) => await RunAsync ( enumerator , cancellationTokenSource . Token ) . ConfigureAwait ( false ) ) ;
62+ UnityTaskUtil . RunOnUnityThread ( async ( ) => await RunAsync ( enumerator , cancellationTokenSource . Token ) ) ;
6363 }
64-
64+
6565 /// <summary>
6666 /// Stop all coroutines that have been started with CoroutineRunner
6767 /// </summary>
@@ -70,12 +70,12 @@ public static void StopAll()
7070 cancellationTokenSource . Cancel ( ) ;
7171 cancellationTokenSource = new CancellationTokenSource ( ) ;
7272 }
73-
73+
7474 private static void OnApplicationQuitting ( )
7575 {
7676 StopAll ( ) ;
7777 }
78-
78+
7979 private static async Task RunAsync ( IEnumerator routine , CancellationToken token )
8080 {
8181 var coroutine = RunCoroutine ( routine ) ;
@@ -85,17 +85,17 @@ private static async Task RunAsync(IEnumerator routine, CancellationToken token)
8585 await Task . Yield ( ) ;
8686 }
8787 }
88-
88+
8989 private static IEnumerator RunCoroutine ( object state )
9090 {
9191 var processStack = new Stack < IEnumerator > ( ) ;
9292 processStack . Push ( ( IEnumerator ) state ) ;
93-
93+
9494 while ( processStack . Count > 0 )
9595 {
9696 var currentCoroutine = processStack . Peek ( ) ;
9797 var done = false ;
98-
98+
9999 try
100100 {
101101 done = ! currentCoroutine . MoveNext ( ) ;
@@ -105,7 +105,7 @@ private static IEnumerator RunCoroutine(object state)
105105 Debug . LogException ( e ) ;
106106 yield break ;
107107 }
108-
108+
109109 if ( done )
110110 {
111111 processStack . Pop ( ) ;
@@ -121,10 +121,9 @@ private static IEnumerator RunCoroutine(object state)
121121 yield return currentCoroutine . Current ;
122122 }
123123 }
124-
124+
125125 }
126126 }
127-
127+
128128 }
129129}
130-
0 commit comments