Skip to content

API.Service.Coroutine

JuDelCo edited this page May 20, 2021 · 5 revisions

Namespace: Ju.Services

ICoroutineService

This service handles coroutines and their lifecycle.

Coroutine StartCoroutine(ILinkHandler handle, IEnumerator routine);

Refs: ILinkHandler

YieldInstructions

This framework provides also some classes to control the flow of your coroutine:

  • TaskWaitUntil
  • TaskWaitWhile
  • TaskWaitForNextUpdate
  • TaskWaitForNextFixedUpdate
  • TaskWaitForSeconds<T>
  • TaskWaitForFrames<T>

Usage (Examples)

private void StartCoroutines()
{
	Core.Coroutine.CoroutineStart(new ObjectLinkHandler<IService>(this), CustomCoroutine());
}

private IEnumerator CustomCoroutine()
{
	// Yield until the next update tick
	yield return null;

	// Yield until condition is true
	yield return new TaskWaitUntil(condition);

	// Yield until condition is false
	yield return new TaskWaitWhile(condition);

	// Yield until next update
	yield return new TaskWaitForNextUpdate();

	// Yield until next fixed update
	yield return new TaskWaitForNextFixedUpdate();

	// Yield for 2 seconds
	yield return new TaskWaitForSeconds<TimeUpdateEvent>(2f);

	// Yield for 5 frames
	yield return new TaskWaitForFrames<TimeUpdateEvent>(5);

	// Yield for 12 fixed frames
	yield return new TaskWaitForFrames<TimeFixedUpdateEvent>(12);
}

Refs: ILinkHandler

Clone this wiki locally