Skip to content

Instantly share code, notes, and snippets.

@andrijaperovic
Created August 12, 2014 07:19
Show Gist options
  • Save andrijaperovic/325faede94069777905c to your computer and use it in GitHub Desktop.
Save andrijaperovic/325faede94069777905c to your computer and use it in GitHub Desktop.
em example
activity = self
EventMachine.run do
operation = proc {
if activity.new_contents.any?
sc = nil
while sc.nil?
sc = SiteContent.find(activity[:scontent_ids].first) rescue nil
sleep(0.1)
end
sc
else
SiteContent.find(activity[:scontent_ids].first) rescue nil
end
}
callback = proc { |sc|
puts sc.try(:as_json_cairo, {:fields => [:all]}) rescue nil
EventMachine.stop
}
EventMachine.defer(operation, callback)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment