Created
May 21, 2019 16:36
-
-
Save jeremycw/2c65fe4dfee9b5feaccb0413491e0d5e to your computer and use it in GitHub Desktop.
Async Program
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
class FooBar | |
include AsyncProgram::Program | |
attr_accessor :state | |
async_program(:state) do |p| | |
p.while { |data| data.loop == true } | |
p.run { |data| puts "looping" } | |
p.if { |data| data.status == 'ready' } | |
p.run { |data| puts data.status } | |
p.await | |
p.run { |data| fizzle } | |
p.else | |
p.run { |data| puts data.status } | |
p.await | |
p.run { |data| puts "finishing..." } | |
p.end | |
p.end | |
end | |
def fizzle | |
puts "fizzle" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this code snippet the same with the "stackless_coroutines" code snippet ? If it isn't this case is it possible to upload the AsyncProgram module? (i'm very curious to see how this pseudo-async await syntax is implemented)
Thanks!