Skip to content

Instantly share code, notes, and snippets.

@jeremycw
Created May 21, 2019 16:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremycw/2c65fe4dfee9b5feaccb0413491e0d5e to your computer and use it in GitHub Desktop.
Save jeremycw/2c65fe4dfee9b5feaccb0413491e0d5e to your computer and use it in GitHub Desktop.
Async Program
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
@billz96
Copy link

billz96 commented Jul 12, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment