Created
February 5, 2020 14:29
-
-
Save KumoKairo/88779bd4cd820dcca6e7f2bfd077c55f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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