Sha256: 782852e7fd486e1d6a0bd6150da3390d939f8c072f4d8df00ed6504ce88ea994

Contents?: true

Size: 776 Bytes

Versions: 5

Compression:

Stored size: 776 Bytes

Contents

# frozen_string_literal: true

module Grumlin
  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

    def initialize(traversal_start_class, pool: Grumlin.default_pool)
      @traversal_start_class = traversal_start_class
      @pool = pool

      @session_id = SecureRandom.uuid
    end

    def begin
      @traversal_start_class.new(session_id: @session_id)
    end

    def commit
      finalize(COMMIT)
    end

    def rollback
      finalize(ROLLBACK)
    end

    private

    def finalize(action)
      @pool.acquire do |client|
        client.write(action, session_id: @session_id)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grumlin-0.22.4 lib/grumlin/transaction.rb
grumlin-0.22.3 lib/grumlin/transaction.rb
grumlin-0.22.2 lib/grumlin/transaction.rb
grumlin-0.22.1 lib/grumlin/transaction.rb
grumlin-0.22.0 lib/grumlin/transaction.rb