Sha256: 97a75404065787f594092d4af94339666adb1397d7fe0f081a8dbfffa30604b3

Contents?: true

Size: 783 Bytes

Versions: 10

Compression:

Stored size: 783 Bytes

Contents

class EveryActor
  include Celluloid

  def initialize
    @trace = []
    @times = []
    @start = Time.now

    every(1) { log(1) }
    every(2) { log(2) }
    every(1) { log(11) }
    every(2) { log(22) }
  end

  def log(t)
    @trace << t

    offset = Time.now - @start
    @times << offset

    # puts "log(#{t}) @ #{offset}"
  end

  attr_reader :trace
  attr_reader :times
end

RSpec.describe "Celluloid::Actor timers" do
  it "run every(t) task several times" do
    Celluloid.boot

    every_actor = EveryActor.new

    sleep 5.5

    every_actor.times
    trace = every_actor.trace

    Celluloid.shutdown

    expect(trace.count(1)).to be == 5
    expect(trace.count(11)).to be == 5
    expect(trace.count(2)).to be == 2
    expect(trace.count(22)).to be == 2
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
celluloid-0.18.0 spec/celluloid/timer_spec.rb
celluloid-0.17.4 spec/celluloid/timer_spec.rb
celluloid-0.18.0.pre2 spec/celluloid/timer_spec.rb
celluloid-0.18.0.pre spec/celluloid/timer_spec.rb
celluloid-0.17.3 spec/celluloid/timer_spec.rb
celluloid-0.17.2 spec/celluloid/timer_spec.rb
celluloid-0.17.1.2 spec/celluloid/timer_spec.rb
celluloid-0.17.1.1 spec/celluloid/timer_spec.rb
celluloid-0.17.1 spec/celluloid/timer_spec.rb
celluloid-0.17.0 spec/celluloid/timer_spec.rb