Skip to content

Instantly share code, notes, and snippets.

@KumoKairo
Created February 5, 2020 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KumoKairo/88779bd4cd820dcca6e7f2bfd077c55f to your computer and use it in GitHub Desktop.
Save KumoKairo/88779bd4cd820dcca6e7f2bfd077c55f to your computer and use it in GitHub Desktop.
public static class YieldInstructionExtension
{
public static YieldInstructionAwaiter GetAwaiter(this YieldInstruction yieldInstruction)
{
return new YieldInstructionAwaiter(yieldInstruction);
}
}
public class YieldInstructionAwaiter : INotifyCompletion
{
private Action _continuation;
private YieldInstruction _yieldInstruction;
private bool _isCompleted;
public YieldInstructionAwaiter(YieldInstruction yieldInstruction)
{
SOME_AVAILABLE_COROUTINE_RUNNER.StartCoroutine(WaitFor(yieldInstruction));
}
private IEnumerator WaitFor(YieldInstruction yieldInstruction)
{
yield return yieldInstruction;
_isCompleted = true;
_continuation();
}
public bool IsCompleted => _isCompleted;
public void GetResult() { }
public void OnCompleted(Action continuation)
{
_continuation = continuation;
}
}
// Example:
// await new WaitForSeconds(1f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment