Skip to content

Instantly share code, notes, and snippets.

@mediocretes
Created February 28, 2012 19:25
Show Gist options
  • Save mediocretes/1934554 to your computer and use it in GitHub Desktop.
Save mediocretes/1934554 to your computer and use it in GitHub Desktop.
#prone to cursor timeouts:
def old
thing.find(query, options).each do |item|
Enumerator.new do |y|
y << do_formatting_and_stuff(item)
end
end
end
#immune to cursor timeouts? the block form of find can be run with an infinite timeout cursor.
def new
Enumerator.new do |y|
thing.find(query, options.merge({timeout: false})).each do |cursor|
cursor.each do |item|
y << do_formatting_and_stuff(item)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment