Sha256: 0404884831f36b480fc98500db9146b066bad276877f56b59a23b8bccfc91a8a

Contents?: true

Size: 841 Bytes

Versions: 1

Compression:

Stored size: 841 Bytes

Contents

# frozen_string_literal: true

class Ztimer
  # Implements a slot, which represents a block of code to be executed at specified time slot.
  class Slot
    attr_reader :enqueued_at, :expires_at, :recurrency, :callback
    attr_accessor :started_at, :executed_at

    def initialize(enqueued_at, expires_at, recurrency = -1, &callback)
      @enqueued_at = enqueued_at
      @expires_at  = expires_at
      @recurrency  = recurrency
      @callback    = callback
      @started_at  = nil
      @executed_at = nil
      @canceled    = false
    end

    def recurrent?
      @recurrency.positive?
    end

    def reset!
      @expires_at += recurrency if recurrent?
    end

    def canceled?
      @canceled
    end

    def cancel!
      @canceled = true
    end

    def <=>(other)
      @expires_at <=> other.expires_at
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ztimer-1.0.0 lib/ztimer/slot.rb