Created
December 14, 2016 07:30
-
-
Save marionzualo/80019ebb09c2302fcec677e3ee4d4cf7 to your computer and use it in GitHub Desktop.
Fibers first example
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
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