blob: 9cfc0e4527389eb0e2ca625388e64fb898b67186 (
plain)
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
|
using Unity.Jobs;
namespace Pathfinding.Util {
public interface IProgress {
float Progress { get; }
}
/// <summary>
/// A promise that T is being calculated asynchronously.
///
/// The result can be accessed by calling <see cref="Complete"/>. This will block until the calculation is complete.
/// </summary>
public struct Promise<T>: IProgress, System.IDisposable where T : IProgress, System.IDisposable {
public JobHandle handle;
T result;
public Promise(JobHandle handle, T result) {
this.handle = handle;
this.result = result;
}
public bool IsCompleted {
get {
return handle.IsCompleted;
}
}
public float Progress {
get {
return result.Progress;
}
}
public T GetValue () {
return result;
}
public T Complete () {
handle.Complete();
return result;
}
public void Dispose () {
Complete();
result.Dispose();
}
}
}
|