Sha256: 3538bbda11837249b0254dd476a369dbfa193c2294f7d360c974a05bd462e5d3

Contents?: true

Size: 748 Bytes

Versions: 5

Compression:

Stored size: 748 Bytes

Contents

module Ztimer
  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?
      return @recurrency > 0
    end

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

    def canceled?
      return @canceled
    end

    def cancel!
      @canceled = true
    end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ztimer-0.5.0 lib/ztimer/slot.rb
ztimer-0.4.3 lib/ztimer/slot.rb
ztimer-0.4.2 lib/ztimer/slot.rb
ztimer-0.4.1 lib/ztimer/slot.rb
ztimer-0.4.0 lib/ztimer/slot.rb