Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Add NotifyCompletion handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatoly Brizhan committed Feb 28, 2024
1 parent 193de6a commit ded04e3
Show file tree
Hide file tree
Showing 17 changed files with 266 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Better.Extensions.Runtime.Helpers;
using UnityEngine;

namespace Better.Extensions.Runtime
{
public static class AssetBundleRequestAwaiterExtensions
{
public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest self)
{
if (self == null)
{
throw new ArgumentNullException(nameof(self));
}

return new AssetBundleRequestAwaiter(self);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Better.Extensions.Runtime.Helpers;
using UnityEngine;

namespace Better.Extensions.Runtime
{
public static class AsyncOperationAwaiterExtensions
{
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation self)
{
if (self == null)
{
throw new ArgumentNullException(nameof(self));
}

return new AsyncOperationAwaiter(self);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Better.Extensions.Runtime.Helpers;
using UnityEngine;

namespace Better.Extensions.Runtime
{
public static class ResourceRequestAwaiterExtensions
{
public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest self)
{
if (self == null)
{
throw new ArgumentNullException(nameof(self));
}

return new ResourceRequestAwaiter(self);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Better.Extensions.Runtime.Helpers;
using UnityEngine.Networking;

namespace Better.Extensions.Runtime
{
public static class UnityWebRequestAsyncOperationExtensions
{
public static UnityWebRequestAwaiter GetAwaiter(this UnityWebRequestAsyncOperation self)
{
if (self == null)
{
throw new ArgumentNullException(nameof(self));
}

return new UnityWebRequestAwaiter(self);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Better.Extensions.Runtime.Helpers
{
[DebuggerNonUserCode]
public readonly struct AssetBundleRequestAwaiter : INotifyCompletion
{
private readonly AssetBundleRequest _asyncOperation;
public bool IsCompleted => _asyncOperation.isDone;

public AssetBundleRequestAwaiter(AssetBundleRequest asyncOperation)
{
_asyncOperation = asyncOperation;
}

public void OnCompleted(Action continuation)
{
_asyncOperation.completed += _ => continuation();
}

public Object GetResult()
{
return _asyncOperation.asset;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;

namespace Better.Extensions.Runtime.Helpers
{
[DebuggerNonUserCode]
public readonly struct AsyncOperationAwaiter : INotifyCompletion
{
private readonly AsyncOperation _asyncOperation;
public bool IsCompleted => _asyncOperation.isDone;

public AsyncOperationAwaiter(AsyncOperation asyncOperation)
{
_asyncOperation = asyncOperation;
}

public void OnCompleted(Action continuation)
{
_asyncOperation.completed += _ => continuation();
}

public AsyncOperation GetResult()
{
return _asyncOperation;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;

namespace Better.Extensions.Runtime.Helpers
{
[DebuggerNonUserCode]
public readonly struct ResourceRequestAwaiter : INotifyCompletion
{
private readonly ResourceRequest _asyncOperation;
public bool IsCompleted => _asyncOperation.isDone;

public ResourceRequestAwaiter(ResourceRequest asyncOperation)
{
_asyncOperation = asyncOperation;
}

public void OnCompleted(Action continuation)
{
_asyncOperation.completed += _ => continuation();
}

public ResourceRequest GetResult()
{
return _asyncOperation;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine.Networking;

namespace Better.Extensions.Runtime.Helpers
{
[DebuggerNonUserCode]
public readonly struct UnityWebRequestAwaiter : INotifyCompletion
{
private readonly UnityWebRequestAsyncOperation _asyncOperation;

public bool IsCompleted => _asyncOperation.isDone;

public UnityWebRequestAwaiter(UnityWebRequestAsyncOperation asyncOperation)
{
_asyncOperation = asyncOperation;
}

public void OnCompleted(Action continuation)
{
_asyncOperation.completed += _ => continuation();
}

public UnityWebRequest GetResult()
{
return _asyncOperation.webRequest;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ded04e3

Please sign in to comment.