Last active
June 5, 2019 16:17
-
-
Save swarnimarun/5aef2f295deafdeda80da720042b4068 to your computer and use it in GitHub Desktop.
Yield as the ultimate coroutine
This file contains 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
extends Node | |
func yielder(): | |
print("Holla") | |
yield() | |
return yielder() | |
func returny_yielder(): | |
print(yield()) | |
return returny_yielder() | |
func _ready(): | |
yielder().resume().resume().resume() | |
# this structure can be resumed infinite times theoritically | |
# if even this didn't tingle those neurons | |
# let's try something else | |
returny_yielder().resume("Namaste").resume("Hello").resume("Hi") | |
# PS: This on it's own is rather useless but this gives you all some ideas hopefully | |
# a more sane example would be the function yields multiple times in multiple ways | |
# to accept different kinds of inputs to further do indirect recursive calls using signals as | |
# notifiers look at the notifier example to get some ideas how that could be done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment