Created
July 1, 2012 17:55
-
-
Save yankov/3029115 to your computer and use it in GitHub Desktop.
Stop EM when all iterations are complete
This file contains hidden or 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
# is there a good pattern for this routine? | |
EM.synchrony do | |
size = keys.count | |
counter = 0 | |
# check if each iteration was completed | |
EM::add_periodic_timer( 2 ) do | |
next unless counter == size | |
EM.stop | |
end | |
EM::Synchrony::FiberIterator.new(keys, 2000).each {|key| | |
do_something_with(key).callback { counter += 1; } | |
} | |
end |
khakimov
commented
Jul 2, 2012
yeah, I tried this pattern at another place too: https://github.com/yankov/redis-migrator/blob/master/migrator.rb#L43.
But the point was that it can be more complicated than just comparing a counter, and counter could be changed from various other places.
Anyways, EM turned out to be not the best approach for this job.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment