Skip to content

Instantly share code, notes, and snippets.

@jamonholmgren
Created October 1, 2012 01:51
Show Gist options
  • Save jamonholmgren/3809022 to your computer and use it in GitHub Desktop.
Save jamonholmgren/3809022 to your computer and use it in GitHub Desktop.
Async and spinner helper in action
@hud = spinner_on labelText: "Importing..."
Friend.eq(user: User.current_user).order(name: :asc).fetchAll do |friends|
import_queue = Dispatch::Queue.new("com.clearsightstudio.bigday.import_address_book_contacts")
friend_lookup = []
if friends
friends.each do |f|
friend_lookup << f.name
end
end
num = 0
self.imported_people.each do |person|
if person.first_name && person.first_name.length > 0
num += 1
import_queue.async do
# TODO: Add more sophisticated deduplication code.
# Right now, I'm only checking first/last names to prevent duplicates.
# Obviously this will be inadequate in the future.
full_name = "#{person.first_name} #{person.last_name}"
unless friend_lookup.include? full_name
Dispatch::Queue.main.async do
update_hud(full_name)
end
p = Friend.new
p.name = full_name
p.user = User.current_user
p.save
end
end
end
end
import_queue.async do
Dispatch::Queue.main.async do
done_importing_friends
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment