Skip to content

Instantly share code, notes, and snippets.

@yankov
Created July 1, 2012 17:55
Show Gist options
  • Save yankov/3029115 to your computer and use it in GitHub Desktop.
Save yankov/3029115 to your computer and use it in GitHub Desktop.
Stop EM when all iterations are complete
# 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
@yankov
Copy link
Author

yankov commented Jul 2, 2012

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