Sha256: 7abb2f60213499d6f1be34a48122304a000a68ca1e8f0806dce193e31534656e
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Proc do describe '#throttle' do it 'should throttle proc call' do count = 0 proc = Proc.new do |increment| count += increment || 1 end throttled_proc = proc.throttle(1) throttled_proc.call count.should eql(1) sleep 1.1 10.times do throttled_proc.call sleep 0.2 end sleep 1.1 count.should eql(4) sleep 1.1 throttled_proc.call(10) count.should eql(14) end end describe '#debounce' do it 'should debounce proc call' do count = 0 proc = Proc.new do |increment| count += increment || 1 end throttled_proc = proc.debounce(1) 10.times do throttled_proc.call end sleep 1.1 count.should eql(1) throttled_proc.call sleep 1.1 count.should eql(2) throttled_proc.call(10) sleep 1.1 count.should eql(12) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
proc-throttle-0.1.0 | spec/throttle_spec.rb |