Skip to content

Commit 2fb8f43

Browse files
authored
Merge pull request #9 from coryleach/dev
Minor Bump for WebGL Compatibility Changes
2 parents ec20cf0 + b784184 commit 2fb8f43

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
#### Using UnityPackageManager (for Unity 2019.3 or later)
2020
Open the package manager window (menu: Window > Package Manager)<br/>
2121
Select "Add package from git URL...", fill in the pop-up with the following link:<br/>
22-
https://github.com/coryleach/UnityAsync.git#1.0.5<br/>
22+
https://github.com/coryleach/UnityAsync.git#1.0.6<br/>
2323

2424
#### Using UnityPackageManager (for Unity 2019.1 or later)
2525

2626
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
2727
```js
2828
{
2929
"dependencies": {
30-
"com.gameframe.async": "https://github.com/coryleach/UnityAsync.git#1.0.5",
30+
"com.gameframe.async": "https://github.com/coryleach/UnityAsync.git#1.0.6",
3131
...
3232
},
3333
}
@@ -93,7 +93,7 @@ await Awaiters.MainUnityThread;
9393

9494
## Show your support
9595
Give a ⭐️ if this project helped you!
96-
{AUTHOR.KOFI}
96+
9797

9898
***
9999
_This README was generated with ❤️ by [Gameframe.Packages](https://github.com/coryleach/unitypackages)_

Runtime/Coroutines/CoroutineRunner.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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-

Runtime/UnityTaskUtil.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private static void Install()
2020
}
2121

2222
public static bool CurrentThreadIsUnityThread => UnityThreadId == Thread.CurrentThread.ManagedThreadId;
23-
23+
2424
public static TaskScheduler UnityTaskScheduler { get; private set; }
2525

2626
public static TaskFactory<UnityEngine.Object> UnityTaskFactory { get; private set; }
@@ -42,7 +42,7 @@ public static CoroutineWrapper StartCancelableCoroutineAsync(IEnumerator corouti
4242
RunOnUnityScheduler(() => { host.StartCoroutine(wrapper.Run(coroutine)); });
4343
return wrapper;
4444
}
45-
45+
4646
/// <summary>
4747
/// Invokes an action on the Unity main thread.
4848
/// Will invoke immediately if already on the main thread.
@@ -75,10 +75,10 @@ public static async Task<T> RunOnUnityThreadAsync<T>(Func<T> func)
7575
}
7676
var taskFactory = new TaskFactory<T>(UnityTaskScheduler);
7777
var task = taskFactory.StartNew(func);
78-
await task.ConfigureAwait(false);
78+
await task;
7979
return task.Result;
8080
}
81-
81+
8282
/// <summary>
8383
/// Runs the given action on the Unity main thread
8484
/// Will invoke immediately if already on the main thread
@@ -94,7 +94,7 @@ public static async Task RunOnUnityThreadAsync(Action action)
9494
}
9595
var taskFactory = new TaskFactory(UnityTaskScheduler);
9696
var task = taskFactory.StartNew(action);
97-
await task.ConfigureAwait(false);
97+
await task;
9898
}
9999

100100
/// <summary>
@@ -113,7 +113,7 @@ public static void RunOnUnityThread(Action action)
113113
UnitySynchronizationContext.Post(_=> action(), null);
114114
}
115115
}
116-
116+
117117
/// <summary>
118118
/// Runs the given async delegate on the Unity main thread
119119
/// </summary>
@@ -151,10 +151,10 @@ public static async Task<T> InstantiateAsync<T>(T prefab, Transform parent) wher
151151
instance.name = prefab.name;
152152
return instance;
153153
});
154-
await task.ConfigureAwait(false);
154+
await task;
155155
return task.Result as T;
156156
}
157-
157+
158158
/// <summary>
159159
/// Instantiate a prefab asynchronously
160160
/// Always creates a task on the Unity task scheduler even if already on the main thread.
@@ -170,9 +170,9 @@ public static async Task<T> InstantiateAsync<T>(T prefab) where T : UnityEngine.
170170
instance.name = prefab.name;
171171
return instance;
172172
});
173-
await task.ConfigureAwait(false);
173+
await task;
174174
return task.Result as T;
175175
}
176176

177177
}
178-
}
178+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.gameframe.async",
33
"displayName": "Gameframe.Async",
4-
"version": "1.0.5",
4+
"version": "1.0.6",
55
"description": "> Async task utility package for Unity \n> Helper methods for starting tasks on the Unity thread. \n> Start and await coroutines from any thread.",
66
"keywords": [],
77
"author": {

0 commit comments

Comments
 (0)