Skip to content

Instantly share code, notes, and snippets.

@swarnimarun
Last active June 5, 2019 16:17
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 swarnimarun/5aef2f295deafdeda80da720042b4068 to your computer and use it in GitHub Desktop.
Save swarnimarun/5aef2f295deafdeda80da720042b4068 to your computer and use it in GitHub Desktop.
Yield as the ultimate coroutine
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