Skip to content

Instantly share code, notes, and snippets.

@zdavatz
Created March 14, 2011 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdavatz/868992 to your computer and use it in GitHub Desktop.
Save zdavatz/868992 to your computer and use it in GitHub Desktop.
id_server.rb
require 'odba/persistable'
require 'thread'
module ODBA
class IdServer
include Persistable
ODBA_SERIALIZABLE = ['@ids']
ODBA_EXCLUDE_VARS = ['@mutex']
def initialize
@ids = {}
end
def next_id(key, startval=1)
@mutex ||= Mutex.new
res = nil
@mutex.synchronize {
@ids[key] ||= (startval - 1)
res = @ids[key] += 1
}
odba_store
res
end
end
end
@mhatakeyama
Copy link

'@ids'
'@mutex'

is string data, not variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment