Skip to content

Instantly share code, notes, and snippets.

@jeremycw
jeremycw / stackless_coroutine.rb
Last active July 12, 2020 09:18
Stackless Coroutine implementation in ruby
#Copyright (c) 2019 Jeremy Williams
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all
@jeremycw
jeremycw / async.rb
Created May 21, 2019 16:36
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 }