Last active
December 17, 2015 00:09
-
-
Save namelessjon/5518574 to your computer and use it in GitHub Desktop.
Rough sketch of the internal organisation for game app. Is this kind of thing safe with respect to potentially overlapping calls of the various methods on rooms that might iterate over it while other methods add/delete from it?
This file contains hidden or 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
class Webapp | |
include Reel::App | |
get '/' do | |
rooms = Actor[:rooms].list_rooms | |
# serialize and stuff here | |
end | |
post '/:room' do | |
# do some stuff | |
Actor[:rooms].add(room) | |
end | |
post '/:room/:dice' do | |
Actor[:rooms].roll_dice(room, dice) | |
end | |
end | |
# Maybe other ways of interacting with Rooms here, e.g. a TCP server too. | |
# Talking with @benlangfeld, I'd be safe, so long as there were no methods | |
# on actors called by any of the methods on Rooms, which could then interrupt | |
# the otherwise serial nature of the calls. | |
# He therefore suggested using an immutable structure, such as those provided | |
# by Hamster. | |
class Rooms | |
include Celluloid::Actor | |
def initialize | |
@rooms = Hamster.hash | |
end | |
# Add room to app | |
def add(room) | |
# make a new room. Probably a PORO, maybe another actor. | |
end | |
# list rooms iterates over rooms | |
def list_rooms | |
@rooms.map { |id, room| [id, room.title] } | |
end | |
# this might delete rooms from the hash | |
every(60) { check_for_empty_rooms } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment