Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- using UnityEngine;
- public static class AsyncOperationExtensions
- {
- public static AsyncTools.Awaiter GetAwaiter(this AsyncOperation asyncOp) => new AsyncOperationAwaiter(asyncOp);
- private class AsyncOperationAwaiter : AsyncTools.Awaiter
- {
- private readonly AsyncOperation asyncOp;
- public AsyncOperationAwaiter(AsyncOperation asyncOp)
- {
- this.asyncOp = asyncOp;
- }
- public override bool IsCompleted => asyncOp.isDone;
- public override void OnCompleted(Action action)
- {
- Task.Factory.StartNew(async () =>
- {
- while (asyncOp.isDone == false)
- {
- await 0;
- }
- action();
- },
- CancellationToken.None,
- TaskCreationOptions.None,
- UnityScheduler.UpdateScheduler);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement