Skip to content

Instantly share code, notes, and snippets.

@marionzualo
Created December 14, 2016 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marionzualo/80019ebb09c2302fcec677e3ee4d4cf7 to your computer and use it in GitHub Desktop.
Save marionzualo/80019ebb09c2302fcec677e3ee4d4cf7 to your computer and use it in GitHub Desktop.
Fibers first example
def find_in_batches
index = 0
chunk_size = 2
while batch = query_batch(index, chunk_size)
return if batch.length == 0
yield batch
index += 1
end
end
def query_batch(index, chunk_size)
range_beginning = index * chunk_size
large_dataset[range_beginning...(range_beginning+2)]
end
def large_dataset
[
"Vhils",
"AKACORLEONE",
"Pixel Pancho",
"+-",
"Kruella D'Enfer",
"Tamara Alves",
"Add Fuel",
"MAR",
"Eime",
"Bordalo II",
"Felipe Pantone",
"Ernest Zacharevic",
"Wasted Rita",
"Sainer"
]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment