lib/signalize.rb in signalize-1.0.1 vs lib/signalize.rb in signalize-1.1.0
- old
+ new
@@ -1,19 +1,20 @@
# frozen_string_literal: true
+require "concurrent"
require_relative "signalize/version"
module Signalize
class Error < StandardError; end
class << self
- def class_variablize(name)
+ def global_map_accessor(name)
define_singleton_method "#{name}" do
- class_variable_get("@@#{name}")
+ GLOBAL_MAP[name]
end
define_singleton_method "#{name}=" do |value|
- class_variable_set("@@#{name}", value)
+ GLOBAL_MAP[name] = value
end
end
end
def self.cycle_detected
@@ -25,28 +26,30 @@
OUTDATED = 1 << 2
DISPOSED = 1 << 3
HAS_ERROR = 1 << 4
TRACKING = 1 << 5
+ GLOBAL_MAP = Concurrent::Map.new
+
# Computed | Effect | nil
- @@eval_context = nil
- class_variablize :eval_context
+ global_map_accessor :eval_context
+ self.eval_context = nil
# Effects collected into a batch.
- @@batched_effect = nil
- class_variablize :batched_effect
- @@batch_depth = 0
- class_variablize :batch_depth
- @@batch_iteration = 0
- class_variablize :batch_iteration
+ global_map_accessor :batched_effect
+ self.batched_effect = nil
+ global_map_accessor :batch_depth
+ self.batch_depth = 0
+ global_map_accessor :batch_iteration
+ self.batch_iteration = 0
# NOTE: we have removed the global version optimization for Ruby, due to
# the possibility of long-running server processes and the number reaching
# a dangerously high integer value.
#
- # @@global_version = 0
- # class_variablize :global_version
+ # global_map_accessor :global_version
+ # self.global_version = 0
Node = Struct.new(
:_version,
:_source,
:_prev_source,
@@ -434,9 +437,13 @@
def to_s
@value.to_s
end
def peek = @value
+
+ def inspect
+ "#<#{self.class} value: #{peek.inspect}>"
+ end
end
class Computed < Signal
attr_accessor :_compute, :_sources, :_flags