Class: Factbase::SyncFactbase
- Inherits:
-
Object
- Object
- Factbase::SyncFactbase
- Defined in:
- lib/factbase/sync/sync_factbase.rb
Overview
A synchronous thread-safe factbase.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(origin, mutex = Mutex.new) ⇒ SyncFactbase
constructor
Constructor.
-
#insert ⇒ Factbase::Fact
Insert a new fact and return it.
-
#query(term, maps = nil) ⇒ Object
Create a query capable of iterating.
-
#to_term(query) ⇒ Factbase::Term
Convert a query to a term.
-
#txn {|Factbase| ... } ⇒ Factbase::Churn
Run an ACID transaction.
Constructor Details
#initialize(origin, mutex = Mutex.new) ⇒ SyncFactbase
Constructor.
20 21 22 23 |
# File 'lib/factbase/sync/sync_factbase.rb', line 20 def initialize(origin, mutex = Mutex.new) @origin = origin @mutex = mutex end |
Instance Method Details
#insert ⇒ Factbase::Fact
Insert a new fact and return it.
27 28 29 30 31 |
# File 'lib/factbase/sync/sync_factbase.rb', line 27 def insert try_lock do @origin.insert end end |
#query(term, maps = nil) ⇒ Object
Create a query capable of iterating.
43 44 45 46 47 |
# File 'lib/factbase/sync/sync_factbase.rb', line 43 def query(term, maps = nil) term = to_term(term) if term.is_a?(String) require_relative 'sync_query' Factbase::SyncQuery.new(@origin.query(term, maps), @mutex, self) end |
#to_term(query) ⇒ Factbase::Term
Convert a query to a term.
36 37 38 |
# File 'lib/factbase/sync/sync_factbase.rb', line 36 def to_term(query) @origin.to_term(query) end |
#txn {|Factbase| ... } ⇒ Factbase::Churn
Run an ACID transaction.
52 53 54 55 56 |
# File 'lib/factbase/sync/sync_factbase.rb', line 52 def txn @origin.txn do |fbt| yield Factbase::SyncFactbase.new(fbt, @mutex) end end |