Skip to content

Commit

Permalink
FSEvents::Stream now stores the time of its last event.
Browse files Browse the repository at this point in the history
  • Loading branch information
ymendel committed Jun 15, 2008
1 parent b1d84c4 commit 68ca385
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/fsevents/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module FSEvents
class Stream
attr_reader :stream
attr_reader :stream, :last_event
attr_reader :allocator, :context, :paths, :since, :latency, :flags, :callback

class StreamError < StandardError; end
Expand Down Expand Up @@ -37,6 +37,8 @@ def stream_callback
event_count.times { |i| events << Event.new(event_IDs[i], paths[i], self) }

callback.call(events)

update_last_event
end
end

Expand All @@ -46,6 +48,11 @@ def schedule

def start
OSX.FSEventStreamStart(stream) or raise StreamError, 'Could not start stream'
update_last_event
end

def update_last_event
@last_event = Time.now
end

def startup
Expand Down
23 changes: 23 additions & 0 deletions spec/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
@callback.expects(:call).with(events)
@proc.call(*@args)
end

it "should update the stream's last event" do
@stream.expects(:update_last_event)
@proc.call(*@args)
end
end
end

Expand Down Expand Up @@ -382,6 +387,24 @@
it 'should not raise a StreamError exception if the stream could be started' do
lambda { @stream.start }.should_not raise_error(FSEvents::Stream::StreamError)
end

it 'should update its last event' do
@stream.expects(:update_last_event)
@stream.start
end
end

it 'should update its last event' do
@stream.should respond_to(:update_last_event)
end

describe 'updating its last event' do
it 'should store the last event time' do
now = Time.now
Time.stubs(:now).returns(now)
@stream.update_last_event
@stream.last_event.should == now
end
end

it 'should start up' do
Expand Down

0 comments on commit 68ca385

Please sign in to comment.