mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-17 04:30:13 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bb44066c0 | ||
|
|
305c4aaa07 | ||
|
|
42d627f3ba | ||
|
|
6dd2b464a3 | ||
|
|
32f24cf8f8 | ||
|
|
4a89e3ea86 |
@@ -536,7 +536,7 @@ How to create async iterator, C# 8.0 supports async iterator(`async yield return
|
|||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// IAsyncEnumerable, C# 8.0 version of async iterator. ( do not use this style, IAsyncEnumerable is not controled in UniTask).
|
// IAsyncEnumerable, C# 8.0 version of async iterator. ( do not use this style, IAsyncEnumerable is not controled in UniTask).
|
||||||
public async IAsyncEnumerable<int> MyEveryUpdate([EnumeratorCancellation]CancellationToken cancelationToken)
|
public async IAsyncEnumerable<int> MyEveryUpdate([EnumeratorCancellation]CancellationToken cancelationToken = default)
|
||||||
{
|
{
|
||||||
var frameCount = 0;
|
var frameCount = 0;
|
||||||
await UniTask.Yield();
|
await UniTask.Yield();
|
||||||
|
|||||||
@@ -120,24 +120,6 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
completionSource.TrySetResult(false);
|
completionSource.TrySetResult(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TrySetCanceled(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
state = -2;
|
|
||||||
return completionSource.TrySetCanceled(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TrySetComplete()
|
|
||||||
{
|
|
||||||
state = -2;
|
|
||||||
return completionSource.TrySetResult(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TrySetException(Exception error)
|
|
||||||
{
|
|
||||||
state = -2;
|
|
||||||
return completionSource.TrySetException(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetResult(T value)
|
public void SetResult(T value)
|
||||||
{
|
{
|
||||||
Current = value;
|
Current = value;
|
||||||
|
|||||||
@@ -31,7 +31,13 @@ namespace Cysharp.Threading.Tasks
|
|||||||
#endif
|
#endif
|
||||||
this.Error = unityWebRequest.error;
|
this.Error = unityWebRequest.error;
|
||||||
this.ResponseCode = unityWebRequest.responseCode;
|
this.ResponseCode = unityWebRequest.responseCode;
|
||||||
this.Text = unityWebRequest.downloadHandler.text;
|
if (UnityWebRequest.downloadHandler != null)
|
||||||
|
{
|
||||||
|
if (unityWebRequest.downloadHandler is DownloadHandlerBuffer dhb)
|
||||||
|
{
|
||||||
|
this.Text = dhb.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Message
|
public override string Message
|
||||||
@@ -40,7 +46,14 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
if (msg == null)
|
if (msg == null)
|
||||||
{
|
{
|
||||||
msg = Error + Environment.NewLine + Text;
|
if (Text != null)
|
||||||
|
{
|
||||||
|
msg = Error + Environment.NewLine + Text;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = Error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "com.cysharp.unitask",
|
"name": "com.cysharp.unitask",
|
||||||
"displayName": "UniTask",
|
"displayName": "UniTask",
|
||||||
"version": "2.0.24",
|
"version": "2.0.25",
|
||||||
"unity": "2018.4",
|
"unity": "2018.4",
|
||||||
"description": "Provides an efficient async/await integration to Unity.",
|
"description": "Provides an efficient async/await integration to Unity.",
|
||||||
"keywords": [ "async/await", "async", "Task", "UniTask" ],
|
"keywords": [ "async/await", "async", "Task", "UniTask" ],
|
||||||
|
|||||||
@@ -476,25 +476,9 @@ public class SandboxMain : MonoBehaviour
|
|||||||
|
|
||||||
async UniTaskVoid Start()
|
async UniTaskVoid Start()
|
||||||
{
|
{
|
||||||
var cts = new CancellationTokenSource();
|
var url = "http://google.com/404";
|
||||||
okButton.onClick.AddListener(() =>
|
var webRequestAsyncOperation = UnityWebRequest.Get(url).SendWebRequest();
|
||||||
{
|
await webRequestAsyncOperation.ToUniTask();
|
||||||
cts.Cancel();
|
|
||||||
});
|
|
||||||
|
|
||||||
//// Nanika();
|
|
||||||
|
|
||||||
|
|
||||||
//await UniTask.Yield();
|
|
||||||
|
|
||||||
|
|
||||||
await MyEveryUpdate().Select(x => x).Where(x => x % 2 == 0).ForEachAsync(x =>
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.Log(x + ":" + Time.frameCount);
|
|
||||||
}, cts.Token);
|
|
||||||
|
|
||||||
|
|
||||||
// this.GetCancellationTokenOnDestroy()
|
|
||||||
|
|
||||||
//PlayerLoopInfo.Inject();
|
//PlayerLoopInfo.Inject();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user