Skip to content

Instantly share code, notes, and snippets.

@taylorbrooks
Last active September 29, 2016 18:09
Show Gist options
  • Save taylorbrooks/add8cdb202091eadf765227e36f0e9e2 to your computer and use it in GitHub Desktop.
Save taylorbrooks/add8cdb202091eadf765227e36f0e9e2 to your computer and use it in GitHub Desktop.
# Is it thread-safe if this class is instantiated based on a new HTTP req
# and two separate reqs happen at the same time?
class BingBong
attr_reader :uuid, :person
def initialize(person:,)
@uuid = SecureRandom.uuid
@person = person
end
def execute
fetch_preferences
Thread.new do
fetch_suggested_restaurants
end
Thread.new do
fetch_suggested_music
end
end
def fetch_preferences
@prefs ||= PreferenceService.new(person_id: person.id).execute
end
def fetch_suggested_restaurants
food = FoodService.new(preferences: @prefs, person_id: person.id).execute
RPCPublisher.publish(uuid, food)
end
def fetch_suggested_music
music = MusicService.new(preferences: @prefs, person_id: person.id).execute
RPCPublisher.publish(uuid, music)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment