Class AsyncRequest
Base class for representing an asynchronous request. AsyncRequest is a bit like Task, but doesn't always execute on the main thread like Task in Unity. Another difference, is that several different lambda functors can operate on different parts of the data in parallel. Once all lambda functors have completed, the request is marked as complete.
Namespace: Unity.Simulation
Syntax
public abstract class AsyncRequest
Fields
_executionContext
The execution context that this request was started with.
Declaration
protected AsyncRequest.ExecutionContext _executionContext
Field Value
Type | Description |
---|---|
AsyncRequest.ExecutionContext |
_state
Property which holds whether or not the request has started and or has an error.
Declaration
protected AsyncRequest.State _state
Field Value
Type | Description |
---|---|
AsyncRequest.State |
Properties
_executionHandles
Handles for asynchronous requests. Type depends on the ExecutionContext used to execute the request. This will be either JobHandle[] or a CountdownEvent
Declaration
protected object _executionHandles { get; set; }
Property Value
Type | Description |
---|---|
Object |
completed
Returns true if the request has completed.
Declaration
public bool completed { get; }
Property Value
Type | Description |
---|---|
Boolean |
defaultExecutionContext
Property specifying the default ExecutionContext to use when executing requests.
Declaration
public static AsyncRequest.ExecutionContext defaultExecutionContext { get; set; }
Property Value
Type | Description |
---|---|
AsyncRequest.ExecutionContext |
error
Returns true if the request has encountered an error.
Declaration
public bool error { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
jobsInFlight
Declaration
public abstract int jobsInFlight { get; }
Property Value
Type | Description |
---|---|
Int32 |
maxAsyncRequestFrameAge
Specifying a non zero value for this property will cause the the SDK to complete requests whenever a request is about to be older than this property value. This is useful when using native containers inside of requests that use a temp allocator, which has a 4 frame limit before being deallocated. This applies to asynchronous execution only, i.e. ThreadPool and JobSystem.
Declaration
public static int maxAsyncRequestFrameAge { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
maxJobSystemParallelism
When using the Unity Job System, jobs will chain after previous jobs in such a way as to only utilize maxJobSystemParallelism worker threads at any time. i.e. Setting this to 1 will result in jobs chaining back to back with no parallelism.
Declaration
public static int maxJobSystemParallelism { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
requestFrameAgeToAutoComplete
Similar to the above static property, this instanced version can also be set. If set, then this value will be used, otherise, if left at 0, then the static property value will be used instead.
Declaration
public int requestFrameAgeToAutoComplete { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
started
Returns true if the request has started.
Declaration
public bool started { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
AllResultsAreCompleted()
Virtual method implemented by derived classes. Called to determine if all results are present and completed.
Declaration
protected virtual bool AllResultsAreCompleted()
Returns
Type | Description |
---|---|
Boolean |
AnyResultHasError()
Virtual method implemented by derived classes. Called to determine if any result had an error.
Declaration
protected virtual bool AnyResultHasError()
Returns
Type | Description |
---|---|
Boolean |
Complete()
Virtual method implemented by derived classes. Completes the request. Called when the request is older than allowed, forcing it to complete.
Declaration
public virtual void Complete()
Reset()
Virtual method implemented by derived classes. Resets the request. Called when returning to the object pool.
Declaration
public virtual void Reset()