Created
September 16, 2013 01:18
-
-
Save 4poc/6575746 to your computer and use it in GitHub Desktop.
Implements a rbot plugin that waits for user input using fibers, just a simple example to show the concept.
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 FiberPlugin < Plugin | |
def fiber(m, params) | |
# imagine this beeing a long (possible infinite) list of something, that is loaded on request | |
data = ('a'...'z').to_a | |
@fiber = Fiber.new do | |
data.each_slice(3) do |partial| | |
m.reply partial.join(', ') + " #{Underline}Type &more for more data." | |
Fiber.yield | |
end | |
end | |
@fiber.resume | |
end | |
def more(m, params) | |
@fiber.resume | |
end | |
end | |
plugin = FiberPlugin.new | |
plugin.map 'fiber' | |
plugin.map 'more' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment