Sha256: 8c5484f6339ad0dc724117bdae098362ea16acc83708e013626f540ebfa9fcf8

Contents?: true

Size: 878 Bytes

Versions: 1

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

require_relative 'base'

module Legion
  module Extensions
    module Actors
      class Once
        include Legion::Extensions::Actors::Base

        def initialize
          return if disabled?

          if respond_to? :functions
            functions.each do
              function
              @task = Concurrent::ScheduledTask.execute(delay) do
                use_runner ? runner : manual
              end
            end
          else
            @task = Concurrent::ScheduledTask.execute(delay) do
              use_runner ? runner : manual
            end
          end
        rescue StandardError => e
          Legion::Logging.error e
        end

        def delay
          1.0
        end

        def cancel
          return if disabled?

          @task.cancel unless @task.cancelled?
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legionio-0.2.0 lib/legion/extensions/actors/once.rb