class Tasklike


Summary:

The basis for all task-like coroutines. Start a new task-like coroutine by calling this.StartTask(IEnumerator routine) or simply create one without starting it by calling its constructor like so: new Tasklike(IEnumerator routine, MonoBehaviour owner)

You can check whether or not the coroutine has finished by checking the IsRunning and IsCompleted properties. If there is an error while running the coroutine, the IsFaulted property will be set to true, and IsRunning will be set to false.


Code Example:

using System.Collections;
using UnityEngine;
using TasklikeCoroutines;

public class ExampleScript : MonoBehaviour {

	
public IEnumerator Start() {

		
Tasklike tasklike = new Tasklike( ExampleRoutine(), this ).Start();
		
yield return tasklike.Yield();

		
// Code here will execute 2 seconds after Start
	
}

	
public IEnumerator ExampleRoutine() {
		
yield return new WaitForSeconds(2);
	
}
}

Constructor:

Signature Description
Tasklike(IEnumerator enumerator, MonoBehaviour owner) Constructor for a new task-like coroutine. The 'enumerator' parameter is the routine which will be run, and the 'owner' parameter is the MonoBehaviour which is running the task.

Properties:

Name Description
Coroutine coroutine When the task-like coroutine is running, this field holds the Unity-style coroutine which is actually running the task.
object current Contains the last value which was yielded by the task-like coroutine.
bool IsCompleted Is set to true when the routine is completed successfully.
bool IsRunning Is set to true while the routine is running.
bool IsFaulted Is set to true if the routine throws an error while running.

Static Methods:

Return Type Signature Description
Tasklike FromYieldable(object yieldable, MonoBehaviour owner) Creates a task-like coroutine from a generic object. The given object must be yieldable, meaning it must be of type Tasklike, IEnumerator, or some kind of YieldInstruction such as WaitForSeconds.
Tasklike<T> FromYieldable<T>(object yieldable, MonoBehaviour owner) Creates a task-like coroutine which can store a result of type T from a generic object. The given object must be yieldable, meaning it must be of type Tasklike, IEnumerator, or some kind of YieldInstruction such as WaitForSeconds.
Tasklike All(MonoBehaviour owner, params Tasklike[] tasklikes)

All(IList<Tasklike> tasklikes, MonoBehaviour owner)
Creates a task-like coroutine on the 'owner' which only completes once all the given 'tasklikes' have completed, and starts that task immediately.
If you wish to create a task-like coroutine with the same functionality which doesn't start immediately, construct one using YieldAll() as the enumerator.
Tasklike<T> All<T>(MonoBehaviour owner, params Tasklike<T>[] tasklikes)

All<T>(IList<Tasklike<T>> tasklikes, MonoBehaviour owner)
Creates a task-like coroutine on the 'owner' which can store a result of type T and only completes once all the given 'tasklikes' have completed, then starts that task immediately.
If you wish to create a task-like coroutine with the same functionality which doesn't start immediately, construct one using YieldAll<T>() as the enumerator.
Tasklike AllYieldables(MonoBehaviour owner, params object[] yieldables)

AllYieldables(IList<object> yieldables, MonoBehaviour owner)
Creates a task-like coroutine on the 'owner' which only completes once all the given 'yieldables' have completed, and starts that task immediately.
The given 'yieldables' must be of type Tasklike, IEnumerator or some kind of YieldInstruction such as WaitForSeconds.
Tasklike<T> AllYieldables<T>(MonoBehaviour owner, params object[] yieldables)

AllYieldables<T>(IList<object<T>> tasklikes, MonoBehaviour owner)
Creates a task-like coroutine on the 'owner' which can store a result of type T and only completes once all the given 'tasklikes' have completed, then starts that task immediately.
The given 'yieldables' must be of type Tasklike, IEnumerator or some kind of YieldInstruction such as WaitForSeconds.
IEnumerator YieldAll(params Coroutine[] coroutines)

YieldAll(IList<Coroutine> coroutines)
Returns an IEnumerator which yields the given 'coroutines' one at a time.
IEnumerator YieldAll(params Tasklike[] tasklikes)

YieldAll(IList<Tasklike> tasklikes)
Returns an IEnumerator which yields null while the given 'tasklikes' are running then breaks once they are all completed.
IEnumerator YieldAll<T>(params Tasklike<T>[] tasklikes)

YieldAll<T>(IList<Tasklike<T>> tasklikes)
Returns an IEnumerator which yields null while the given 'tasklikes' are running, then yields a result of type T once they are all completed, and then breaks.
Tasklike Any(MonoBehaviour owner, params Tasklike[] tasklikes)

Any(IList<Tasklike> tasklikes, MonoBehaviour owner)
Creates a task-like coroutine on the 'owner' which completes when any of the given 'tasklikes' have completed, and starts that task immediately.
If you wish to create a task-like coroutine with the same functionality which doesn't start immediately, construct one using YieldAny() as the enumerator.
Tasklike<T> Any<T>(MonoBehaviour owner, params Tasklike<T>[] tasklikes)

Any<T>(IList<Tasklike<T>> tasklikes, MonoBehaviour owner)
Creates a task-like coroutine on the 'owner' which can store a result of type T and completes when any of the given 'tasklikes' have completed. The task starts immediately.
If you wish to create a task-like coroutine with the same functionality which doesn't start immediately, construct one using YieldAny<T>() as the enumerator.
Tasklike AnyYieldables(MonoBehaviour owner, params object[] yieldables)

AnyYieldables(IList<object> yieldables, MonoBehaviour owner)
Creates a task-like coroutine on the 'owner' which completes when any of the given 'yieldables' have completed, and starts that task immediately.
The given 'yieldables' must be of type Tasklike, IEnumerator or some kind of YieldInstruction such as WaitForSeconds.
Tasklike<T> AnyYieldables<T>(MonoBehaviour owner, params object[] yieldables)

AnyYieldables<T>(IList<object<T>> tasklikes, MonoBehaviour owner)
Creates a task-like coroutine on the 'owner' which can store a result of type T and completes when any of the given 'tasklikes' have completed. The task starts immediately.
The given 'yieldables' must be of type Tasklike, IEnumerator or some kind of YieldInstruction such as WaitForSeconds.
IEnumerator YieldAny(params Tasklike[] tasklikes)

YieldAny(IList<Tasklike> tasklikes)
Returns an IEnumerator which yields null while the given 'tasklikes' are running then breaks when any of them completed.
IEnumerator YieldAny<T>(params Tasklike<T>[] tasklikes)

YieldAny<T>(IList<Tasklike<T>> tasklikes)
Returns an IEnumerator which yields null while the given 'tasklikes' are running, then yields a result of type T when any of them completed, and then breaks.

Instance Methods:

Return Type Signature Description
void Start() Starts the task-like coroutine.
void Stop() Stops the task-like coroutine.
IEnumerator Yield() Returns an enumerator which simply yields the Unity-style coroutine stored within this Tasklike. Use when you want to yield a task-like coroutine within a Unity-style coroutine.
Tasklike Then(IEnumerator nextRoutine) Appends the given enumerator to this task-like coroutine as a routine which will be executed after this coroutine finishes.
Tasklike Then(Tasklike nextTask) Appends the given task-like coroutine to this coroutine so that it can be executed after this coroutine finishes.
Tasklike Then(Action action) Appends the given action to this coroutine so that it can be executed after this coroutine finishes.
Tasklike Then(Action<T> action) Appends the given action to this coroutine so that it can be executed after this coroutine finishes.
This version of Then allows the action to take in a parameter of type T which will be populated by the last result given by the task-like coroutine.