Module: Celluloid::Internals::UUID

### Home Classes Methods

### In Files

- lib/celluloid/internals/uuid.rb

### Methods

- ::generate

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::Incident
- Celluloid::IncidentLogger
- Celluloid::IncidentLogger::Severity
- Celluloid::IncidentReporter
- Celluloid::IncidentReporter::Formatter
- Celluloid::Internals
- Celluloid::Internals::CPUCounter
- Celluloid::Internals::CallChain
- Celluloid::Internals::Handler
- Celluloid::Internals::Handlers
- Celluloid::Internals::Links
- Celluloid::Internals::Logger
- Celluloid::Internals::Logger::WithBacktrace
- Celluloid::Internals::Method
- Celluloid::Internals::Properties
- Celluloid::Internals::Receiver
- Celluloid::Internals::Receivers
- Celluloid::Internals::Registry
- Celluloid::Internals::Response
- Celluloid::Internals::Response::Block
- Celluloid::Internals::Response::Error
- Celluloid::Internals::Response::Success
- Celluloid::Internals::Signals
- Celluloid::Internals::Stack
- Celluloid::Internals::Stack::ActorState
- Celluloid::Internals::Stack::CellState
- Celluloid::Internals::Stack::DisplayBacktrace
- Celluloid::Internals::Stack::Dump
- Celluloid::Internals::Stack::Summary
- Celluloid::Internals::Stack::TaskState
- Celluloid::Internals::Stack::ThreadState
- Celluloid::Internals::TaskSet
- Celluloid::Internals::ThreadHandle
- Celluloid::Internals::UUID
- Celluloid::LogEvent
- Celluloid::Notifications
- Celluloid::Notifications::Fanout
- Celluloid::Notifications::Subscriber
- Celluloid::Probe
- Celluloid::RingBuffer

No matching classes.

# Celluloid::Internals::UUID

Clearly Ruby doesn't have enough UUID libraries This one aims to be fast and simple with good support for multiple threads If there's a better UUID library I can use with similar multithreaded performance, I certainly wouldn't mind using a gem for this!

### Constants

BLOCK_SIZE
PREFIX

### Public Class Methods

generate() click to toggle source

    # File lib/celluloid/internals/uuid.rb, line 17
    def self.generate
      thread = Thread.current

      unless thread.uuid_limit
        @counter_mutex.synchronize do
          block_base = @counter
          @counter += BLOCK_SIZE
          thread.uuid_counter = block_base
          thread.uuid_limit   = @counter - 1
        end
      end

      counter = thread.uuid_counter
      if thread.uuid_counter >= thread.uuid_limit
        thread.uuid_counter = thread.uuid_limit = nil
      else
        thread.uuid_counter += 1
      end

      "#{PREFIX}-#{sprintf('%012x', counter)}".freeze
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.