lib/grumlin/transaction.rb in grumlin-0.22.5 vs lib/grumlin/transaction.rb in grumlin-0.23.0

- old
+ new

@@ -4,18 +4,18 @@ class Transaction attr_reader :session_id include Console - COMMIT = Grumlin::Repository.new.g.step(:tx, :commit).bytecode - ROLLBACK = Grumlin::Repository.new.g.step(:tx, :rollback).bytecode + COMMIT = Grumlin::Repository.new.g.step(:tx, :commit) + ROLLBACK = Grumlin::Repository.new.g.step(:tx, :rollback) - def initialize(traversal_start_class, pool:) + def initialize(traversal_start_class, pool:, middlewares:) @traversal_start_class = traversal_start_class @pool = pool - @session_id = SecureRandom.uuid + @middlewares = middlewares end def begin @traversal_start_class.new(session_id: @session_id) end @@ -28,12 +28,13 @@ finalize(ROLLBACK) end private - def finalize(action) - @pool.acquire do |client| - client.write(action, session_id: @session_id) - end + def finalize(step) + @middlewares.call(traversal: step, + need_results: false, + session_id: @session_id, + pool: @pool) end end end