Last active
September 29, 2016 18:09
-
-
Save taylorbrooks/add8cdb202091eadf765227e36f0e9e2 to your computer and use it in GitHub Desktop.
This file contains 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 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