Class: Gameworks::Servlet::MatchMaker

Inherits:
Base
  • Object
show all
Defined in:
lib/gameworks/servlet/match_maker.rb

Defined Under Namespace

Classes: Promise

Constant Summary collapse

SEATS =
2

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #method_not_allowed, process

Constructor Details

This class inherits a constructor from Gameworks::Servlet::Base

Class Attribute Details

.serverObject

Returns the value of attribute server.



21
22
23
# File 'lib/gameworks/servlet/match_maker.rb', line 21

def server
  @server
end

Class Method Details

.request_game(&blk) ⇒ Object

on the class because I want it persistent



26
27
28
29
30
# File 'lib/gameworks/servlet/match_maker.rb', line 26

def request_game(&blk)
  promise = Promise.new
  promise.demand(&blk)
  queue.push(promise)
end

Instance Method Details

#GET(request) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/gameworks/servlet/match_maker.rb', line 61

def GET(request)
  MatchMaker.server ||= @server
  MatchMaker.request_game do |game|
    request[:async_cb].call [201, {'Location' => "/#{game.id}"}, []]
  end
  [-1, {}, []]
end