forked from muckSponge/UnityAsync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensions.cs
More file actions
75 lines (65 loc) · 3.94 KB
/
Extensions.cs
File metadata and controls
75 lines (65 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using UnityEngine;
using System.Threading;
using System.Threading.Tasks;
using UnityAsync.Awaiters;
using Object = UnityEngine.Object;
namespace UnityAsync
{
public static class Extensions
{
/// <summary>
/// Link the <see cref="UnityAsync.IAwaitInstruction"/>'s lifespan to a <see cref="UnityEngine.Object"/> and
/// configure the type of update cycle it should be evaluated on.
/// </summary>
/// <returns>A continuation with updated params.</returns>
public static AwaitInstructionAwaiter<T> ConfigureAwait<T>(this T i, Object parent, FrameScheduler scheduler) where T : IAwaitInstruction
=> new AwaitInstructionAwaiter<T>(i, parent, scheduler);
/// <summary>
/// Link the <see cref="UnityAsync.IAwaitInstruction"/>'s lifespan to a <see cref="UnityEngine.Object"/>.
/// </summary>
/// <returns>A continuation with updated params.</returns>
public static AwaitInstructionAwaiter<T> ConfigureAwait<T>(this T i, Object parent) where T : IAwaitInstruction
=> new AwaitInstructionAwaiter<T>(i, parent, FrameScheduler.Update);
/// <summary>
/// Configure the type of update cycle it should be evaluated on.
/// </summary>
/// <returns>A continuation with updated params.</returns>
public static AwaitInstructionAwaiter<T> ConfigureAwait<T>(this T i, FrameScheduler scheduler) where T : IAwaitInstruction
=> new AwaitInstructionAwaiter<T>(i, scheduler);
/// <summary>
/// Link the <see cref="UnityAsync.IAwaitInstruction"/>'s lifespan to a
/// <see cref="System.Threading.CancellationToken"/> and configure the type of update cycle it should be
/// evaluated on.
/// </summary>
/// <returns>A continuation with updated params.</returns>
public static AwaitInstructionAwaiter<T> ConfigureAwait<T>(this T i, CancellationToken cancellationToken, FrameScheduler scheduler) where T : IAwaitInstruction
=> new AwaitInstructionAwaiter<T>(i, cancellationToken, scheduler);
/// <summary>
/// Link the <see cref="UnityAsync.IAwaitInstruction"/>'s lifespan to a <see cref="System.Threading.CancellationToken"/>.
/// </summary>
/// <returns>A continuation with updated params.</returns>
public static AwaitInstructionAwaiter<T> ConfigureAwait<T>(this T i, CancellationToken cancellationToken) where T : struct, IAwaitInstruction
=> new AwaitInstructionAwaiter<T>(i, cancellationToken, FrameScheduler.Update);
/// <summary>
/// Encapsulate the <see cref="System.Threading.Tasks.Task"/> in a <see cref="UnityEngine.CustomYieldInstruction"/>
/// so that it can be yielded in an IEnumerator coroutine.
/// </summary>
public static TaskYieldInstruction AsYieldInstruction(this Task t) => new TaskYieldInstruction(t);
/// <summary>
/// Encapsulate the <see cref="System.Threading.Tasks.Task{TResult}"/> in a <see cref="UnityEngine.CustomYieldInstruction"/>
/// so that it can be yielded in an IEnumerator coroutine. The result can be obtained through
/// <see cref="TaskYieldInstruction{T}.Current"/> after yielding.
/// </summary>
public static TaskYieldInstruction<T> AsYieldInstruction<T>(this Task<T> t) => new TaskYieldInstruction<T>(t);
public static SynchronizationContextAwaiter GetAwaiter(this SynchronizationContext s) => new SynchronizationContextAwaiter(s);
public static IEnumeratorAwaiter GetAwaiter(this IEnumerator e) => new IEnumeratorAwaiter(e);
public static YieldInstructionAwaiter GetAwaiter(this YieldInstruction y) => new YieldInstructionAwaiter(y);
public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest r) => new ResourceRequestAwaiter(r);
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation r) => new AsyncOperationAwaiter(r);
public static AwaitInstructionAwaiter<T> GetAwaiter<T>(this T i) where T : struct, IAwaitInstruction => new AwaitInstructionAwaiter<T>(i);
public static AwaitInstructionAwaiter<T> GetAwaiter<T>(in this AwaitInstructionAwaiter<T> a) where T : IAwaitInstruction => a;
}
}