Sha256: 643113169b7067198110e9f0c5f7c7a8a08d5c524ee632c7c04cd0d278b76aeb
Contents?: true
Size: 1.14 KB
Versions: 3
Compression:
Stored size: 1.14 KB
Contents
# Synchronize access and lazy initialize one or more variables in a class # # Load configuration files and thread connection pools on demand rather than # at start time or via a Rails initializer # # Locking: Shared reads and exclusive writes # sync_attr ensures that all reads are shared, meaning that all # reads to attributes can occur at the same time. All writes are exclusive, so # all reads and other writes will be blocked whilst a write takes place. # # Example: # class MyClass # include SyncAttr # # # Create class variable @@http and initialize on the first access # # protecting access by concurrent threads using a Semaphore # sync_cattr_reader :http do # PersistentHTTP.new() # end # # Author: Reid Morrison <reidmo@gmail.com> require 'sync' require 'sync_attr/version' require 'sync_attr/class_attributes' require 'sync_attr/instance_attributes' module SyncAttr # Add class methods and initialize mixin def self.included(base) base.extend(SyncAttr::ClassAttributes::ClassMethods) base.extend(SyncAttr::InstanceAttributes::ClassMethods) base.send(:sync_cattr_init) base.send(:sync_attr_init) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sync_attr-1.0.0 | lib/sync_attr.rb |
sync_attr-0.1.1 | lib/sync_attr.rb |
sync_attr-0.1.0 | lib/sync_attr.rb |