Skip to content

Instantly share code, notes, and snippets.

@4poc
Created September 16, 2013 01:18
Show Gist options
  • Save 4poc/6575746 to your computer and use it in GitHub Desktop.
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.
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